Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y3IYW-0005lv-5i for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Dec 2014 06:02:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y3IYV-00067P-1B for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Dec 2014 06:02:51 +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 1Y3IYU-00067J-DM for pgsql-bugs@postgresql.org; Tue, 23 Dec 2014 06:02:50 +0000 Received: from mwork.nabble.com ([162.253.133.43]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y3IYQ-0006ve-AM for pgsql-bugs@postgresql.org; Tue, 23 Dec 2014 06:02:49 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id 6F16DE83639 for ; Mon, 22 Dec 2014 22:02:43 -0800 (PST) Date: Mon, 22 Dec 2014 23:02:43 -0700 (MST) From: David G Johnston To: pgsql-bugs@postgresql.org Message-ID: <1419314563387-5831793.post@n5.nabble.com> In-Reply-To: <20141222200403.11501.68819@wrigleys.postgresql.org> References: <20141222200403.11501.68819@wrigleys.postgresql.org> Subject: Re: BUG #12319: NPE in JDBC driver when using PgCopyOutputStream MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.3 (/) 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 dhalperi wrote > The following bug has been logged on the website: > > Bug reference: 12319 > Logged by: Daniel Halperin > Email address: > dhalperi@.washington > 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. This isn't the proper forum, jdbc is external to the core project which is what this list is for, but... Until you tell the server you are done sending copy data it doesn't have to parse it and cannot tell you how many records it found. So, no, you cannot close the connection before calling endCopy and expect it to work. I'm not familiar with this particular API but the code you show doesn't seem standard to even the official jdbc project so that otherwise proper list probably isn't the place to ask/report. This is all that is standard: http://jdbc.postgresql.org/documentation/publicapi/index.html If you are using this code: https://github.com/uwescience/myria/blob/master/src/edu/washington/escience/myria/PostgresBinaryTupleWriter.java That library commits the sin of closing a buffer that it did not explicitly create/open. David J. -- View this message in context: http://postgresql.nabble.com/BUG-12319-NPE-in-JDBC-driver-when-using-PgCopyOutputStream-tp5831784p5831793.html Sent from the PostgreSQL - bugs mailing list archive at Nabble.com. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs