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 244350 - NullPointerException at org.netbeans.modules.db.explorer.action.ConnectAction$ConnectionDialogDisplayer.supportsConnectWithoutUsername
Summary: NullPointerException at org.netbeans.modules.db.explorer.action.ConnectAction...
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: Libor Fischmeistr
URL:
Keywords:
: 243582 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-05-07 13:34 UTC by Petr Jiricka
Modified: 2014-08-13 12:36 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 209579


Attachments
stacktrace (6.52 KB, text/plain)
2014-05-07 13:34 UTC, Petr Jiricka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Jiricka 2014-05-07 13:34:03 UTC
Build: NetBeans IDE Dev (Build web-main-779-on-20140503)
VM: Java HotSpot(TM) 64-Bit Server VM, 24.55-b03, Java(TM) SE Runtime Environment, 1.7.0_55-b13
OS: Mac OS X

User Comments:
pjiricka: RESTful services from database -> I chose the bundled Derby connection on the Database Tables panel.




Stacktrace: 
java.lang.NullPointerException
   at org.netbeans.modules.db.explorer.action.ConnectAction$ConnectionDialogDisplayer.supportsConnectWithoutUsername(ConnectAction.java:393)
   at org.netbeans.modules.db.explorer.action.ConnectAction$ConnectionDialogDisplayer.showDialog(ConnectAction.java:190)
   at org.netbeans.modules.db.explorer.DatabaseConnection$5.run(DatabaseConnection.java:1224)
   at org.openide.util.Mutex.doEvent(Mutex.java:1356)
   at org.openide.util.Mutex.readAccess(Mutex.java:355)
   at org.netbeans.modules.db.explorer.DatabaseConnection.showConnectionDialog(DatabaseConnection.java:1221)
Comment 1 Petr Jiricka 2014-05-07 13:34:05 UTC
Created attachment 147161 [details]
stacktrace
Comment 2 Libor Fischmeistr 2014-07-28 11:39:04 UTC
Petre, are you able to reproduce? I was unsuccessful (on Windows).

Changing TM to Next.
Comment 3 matthias42 2014-07-28 18:19:10 UTC
Hey Libor, I thing we are seeing the result of a broken connection definition.

I'm in ConnectAction#supportsConnectWithoutUsername

- dc can't be null, as this would have blown earlier (line 182, 180, 179)
- JDBCDriver#getClassName can't be null (see protection in JDBCDriver#create)
- so this leaves us with DatabaseConnection findJDBCDriver

So findJDBCDriver has to be guarded:

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -390,9 +390,14 @@
         }
 
         private boolean supportsConnectWithoutUsername(DatabaseConnection dc) {
-            return dc.findJDBCDriver().getClassName().equals("org.sqlite.JDBC") || //NOI18N
-                    dc.findJDBCDriver().getClassName().equals("org.h2.Driver"); //NOI18N
+            try {
+                return dc.findJDBCDriver().getClassName().equals("org.sqlite.JDBC") //NOI18N
+                        || dc.findJDBCDriver().getClassName().equals("org.h2.Driver"); //NOI18N
+            } catch (NullPointerException ex) {
+                // Most probably findJDBCDriver failed to find a driver
+                return false;
         }
     }
+    }
 
 }


Maybe DatabaseConnection should gain some documentation/beautification:

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -263,24 +263,33 @@
         setConnectionProperties(connectionProperties);
     }
 
+    /**
+     * Find a registered JDBC driver matching this connection. The function
+     * makes a best effort search, if at least a driver with a matching classname
+     * is present this function will succeed. If a driver with a matching name is
+     * present this will be returned.
+     * 
+     * @return matching JDBC driver for connection or NULL if no match is found
+     */
     public JDBCDriver findJDBCDriver() {
         JDBCDriver[] drvs = JDBCDriverManager.getDefault().getDrivers(drv);
-        if (drivers == null || ! Arrays.equals(drvs, drivers)) {
+        if (drivers == null || !Arrays.equals(drvs, drivers)) {
             drivers = drvs;
 
-            if (drvs.length <= 0) {
-                return null;
-            }
+            JDBCDriver useDriver = null;
 
-            JDBCDriver useDriver = drvs[0];
+            if (drvs.length > 0) {
+                // Fallback - potentially false driver (by name), but at least matches requested class
+                useDriver = drvs[0];
             for (int i = 0; i < drvs.length; i++) {
                 if (drvs[i].getName().equals(getDriverName())) {
                     useDriver = drvs[i];
                     break;
                 }
             }
-            jdbcdrv = useDriver;
+            }
             
+            jdbcdrv = useDriver;
         }
         return jdbcdrv;
     }
Comment 4 Libor Fischmeistr 2014-07-30 12:29:00 UTC
Matthias, thank you for your patch. Applied - http://hg.netbeans.org/core-main/rev/1c5924828bf5
Comment 5 Quality Engineering 2014-07-31 08:59:55 UTC
Integrated into 'main-silver', will be available in build *201407310738* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/1c5924828bf5
User: Libor Fischmeistr <lfischmeistr@netbeans.org>
Log: #244350: NullPointerException at org.netbeans.modules.db.explorer.action.ConnectAction$ConnectionDialogDisplayer.supportsConnectWithoutUsername
Comment 6 matthias42 2014-08-13 12:36:40 UTC
*** Bug 243582 has been marked as a duplicate of this bug. ***