This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244313 - NullPointerException at java.io.ByteArrayInputStream.<init>
Summary: NullPointerException at java.io.ByteArrayInputStream.<init>
Status: VERIFIED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Show Data (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: matthias42
URL:
Keywords: PATCH_AVAILABLE
Depends on:
Blocks:
 
Reported: 2014-05-05 19:36 UTC by Maksim Khramov
Modified: 2015-02-05 18:48 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter: 209528


Attachments
stacktrace (977 bytes, text/plain)
2014-05-05 19:36 UTC, Maksim Khramov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maksim Khramov 2014-05-05 19:36:33 UTC
Build: NetBeans IDE Dev (Build 201405010001)
VM: Java HotSpot(TM) 64-Bit Server VM, 23.21-b01, Java(TM) SE Runtime Environment, 1.7.0_21-b11
OS: Windows 7

User Comments:
mkhramov: Ececute SQL select from SQLIte database using xerial/sqlite-jdbc driver




Stacktrace: 
java.lang.NullPointerException
   at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106)
   at org.sqlite.jdbc3.JDBC3ResultSet.getBinaryStream(JDBC3ResultSet.java:235)
   at org.netbeans.modules.db.dataview.util.DBReadWriteHelper.readResultSet(DBReadWriteHelper.java:226)
   at org.netbeans.modules.db.dataview.output.SQLExecutionHelper.loadDataFrom(SQLExecutionHelper.java:775)
   at org.netbeans.modules.db.dataview.output.SQLExecutionHelper.access$800(SQLExecutionHelper.java:84)
   at org.netbeans.modules.db.dataview.output.SQLExecutionHelper$1Loader.run(SQLExecutionHelper.java:173)
Comment 1 Maksim Khramov 2014-05-05 19:36:35 UTC
Created attachment 147121 [details]
stacktrace
Comment 2 matthias42 2014-11-16 20:06:10 UTC
Please provide steps to reproduce:

- what did you do? (executed SQLs)
- can you provide a sample?

In my tests it worked ok.
Comment 3 Maksim Khramov 2014-11-17 20:55:32 UTC
Product Version: NetBeans IDE Dev (Build 201411150001)
Java: 1.8.0_20; Java HotSpot(TM) 64-Bit Server VM 25.20-b23
Runtime: Java(TM) SE Runtime Environment 1.8.0_20-b26

JDBC driver sqlite-jdbc4-3.8.2-SNAPSHOT.jar from xerial

Issue still there
I just do SELECT * FROM TableName and see this exception.

Once I try to grab table structure I see Error Message Box with Unable to grab structure java.lang.NullPointerException.

Once I do select from table field by field I found that only one field with BLOB type gives me exception mentioned in issue

Hope this helps
Comment 4 matthias42 2014-11-17 21:19:55 UTC
Thank you for rechecking - ok, long story short: The driver is broken. 

The long story:

The problem arises only when the field is null. From:

http://grepcode.com/file/repo1.maven.org/maven2/org.xerial/sqlite-jdbc/3.8.5-pre1/org/sqlite/jdbc3/JDBC3ResultSet.java#JDBC3ResultSet.getBinaryStream%28int%29

getBinaryStream in this case just wraps a byte[] returned fro getBytes - this blows, if the field is set to null. In all fairness, this should really fixed in the driver (=> fetch getBytes into a local variable if that is null, return null and be done with it and don't try to wrap null with a ByteArrayInputStream). It would be nice if you could raise a bug with the developers.

Normaly I'm against fixing driver bugs in the client, but in this case it so short, that its worth it (I think):


# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/matthias/NetBeansProjects/core-main
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java
--- db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java
+++ db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java
@@ -223,7 +223,12 @@
             case Types.LONGVARBINARY:
             case Types.BLOB: {
                 // Load binary data as stream and hold it internally as a pseudoblob
-                InputStream is = rs.getBinaryStream(index);
+                InputStream is = null;
+                try {
+                    is = rs.getBinaryStream(index);
+                } catch (NullPointerException ex) {
+                    // The xerial sqlite-jdbc driver fails to return null and instead throws a NullPointer Exception
+                }
                 if (is == null) {
                     return null;
                 } else {




Grabbing the structure still does not work - looks as if asking sqlite for index info is not such a good idea - I won't fix that.
Comment 5 matthias42 2015-02-01 14:16:40 UTC
The fix was committed as:

http://hg.netbeans.org/core-main/rev/2e10eb3019db

I checked that fix works, but I'd like to ask you to verify the fix. In the next few days a nightly build will be done and a message is placed then in this bug.

If you find the issue fixed, please change the status of this bug to VERIFIED.

Please note: Grab structure will not work as described above - the driver just supplies not enougth information.
Comment 6 Quality Engineering 2015-02-02 02:44:31 UTC
Integrated into 'main-silver', will be available in build *201502020002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/2e10eb3019db
User: Matthias Blaesing <matthias42@netbeans.org>
Log: #244313: Work-around BLOB bug in xerial sqlite jdbc driver (throwing NullPointerException on getBinaryStream instead of returning null)
Comment 7 Maksim Khramov 2015-02-05 18:48:29 UTC
My test DB opens and shows data now with NetBeans IDE Dev (Build 201502050002)