pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #12319: NPE in JDBC driver when using PgCopyOutputStream
2+ messages / 2 participants
[nested] [flat]

* BUG #12319: NPE in JDBC driver when using PgCopyOutputStream
@ 2014-12-22 20:04 dhalperi@cs.washington.edu
  2014-12-23 06:02 ` Re: BUG #12319: NPE in JDBC driver when using PgCopyOutputStream David G Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: dhalperi@cs.washington.edu @ 2014-12-22 20:04 UTC (permalink / raw)
  To: pgsql-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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #12319: NPE in JDBC driver when using PgCopyOutputStream
  2014-12-22 20:04 BUG #12319: NPE in JDBC driver when using PgCopyOutputStream dhalperi@cs.washington.edu
@ 2014-12-23 06:02 ` David G Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David G Johnston @ 2014-12-23 06:02 UTC (permalink / raw)
  To: pgsql-bugs

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/PostgresBinaryTupl...

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-tp5831784p58...
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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2014-12-23 06:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-12-22 20:04 BUG #12319: NPE in JDBC driver when using PgCopyOutputStream dhalperi@cs.washington.edu
2014-12-23 06:02 ` David G Johnston <david.g.johnston@gmail.com>

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