Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y3F5P-0002vQ-Lk for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Dec 2014 02:20:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y3F5P-0004Qx-6b for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Dec 2014 02:20:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y39E9-0001Ab-A9 for pgsql-bugs@postgresql.org; Mon, 22 Dec 2014 20:05:13 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y39E1-0004UU-Lw for pgsql-bugs@postgresql.org; Mon, 22 Dec 2014 20:05:09 +0000 MIME-Version: 1.0 Subject: BUG #12319: NPE in JDBC driver when using PgCopyOutputStream To: pgsql-bugs@postgresql.org From: dhalperi@cs.washington.edu Date: Mon, 22 Dec 2014 20:04:03 +0000 Message-ID: <20141222200403.11501.68819@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.1 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 12319 Logged by: Daniel Halperin Email address: dhalperi@cs.washington.edu PostgreSQL version: 9.3.1 Operating system: Ubuntu 14.04.1 LTS Description: This seems like a fairly natural use case, but it runs into a NullPointerException (NPE): 1. Create a PGCopyOutputStream 2. Write a bunch of data to it, and close the stream 3. Check the number of tuples that were successfully inserted. (full code snippet below). However, this use case results in a NullPointerException at line 162 -- because on OutputStream.close(), the PGCopyOutputStream sets the copyIn to null. CopyManager cpManager = ((PGConnection) jdbcConnection).getCopyAPI(); StringBuilder copyString = new StringBuilder().append("COPY ").append(quote(relationKey)).append(" FROM STDIN WITH BINARY"); CopyIn copyIn = cpManager.copyIn(copyString.toString()); PGCopyOutputStream out = new PGCopyOutputStream(Preconditions.checkNotNull(copyIn, "copyIn")); TupleWriter tw = new PostgresBinaryTupleWriter(out); tw.writeTuples(tupleBatch); tw.done(); // Causes a null pointer exception long inserted = out.endCopy(); From what I can tell, there is currently no reliable way to get the number of tuples after closing the stream. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs