From: dhalperi@cs.washington.edu
To: pgsql-bugs@postgresql.org
Subject: BUG #12319: NPE in JDBC driver when using PgCopyOutputStream
Date: Mon, 22 Dec 2014 20:04:03 +0000
Message-ID: <20141222200403.11501.68819@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: dhalperi@cs.washington.edu
Subject: Re: BUG #12319: NPE in JDBC driver when using PgCopyOutputStream
In-Reply-To: <20141222200403.11501.68819@wrigleys.postgresql.org>
References: <20141222200403.11501.68819@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox