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 201380

Summary: NullPointerException at org.netbeans.modules.db.explorer.node.SchemaNodeProvider$SchemaComparator.compare
Product: db Reporter: dlttorezan
Component: CodeAssignee: Jiri Rechtacek <jrechtacek>
Status: RESOLVED FIXED    
Severity: normal CC: gtg, hdeantoni, MarcosJava, mirceade, ravilan
Priority: P2    
Version: 7.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter: 180811
Attachments: stacktrace
stacktrace
Proposed patch

Description dlttorezan 2011-08-27 16:15:21 UTC
Build: NetBeans IDE 7.0.1 (Build 201107282000)
VM: Java HotSpot(TM) Client VM, 21.0-b17, Java(TM) SE Runtime Environment, 1.7.0-b147
OS: Windows 7

Stacktrace: 
java.lang.NullPointerException
   at org.netbeans.modules.db.explorer.node.SchemaNodeProvider$SchemaComparator.compare(SchemaNodeProvider.java:149)
   at org.netbeans.modules.db.explorer.node.SchemaNodeProvider$SchemaComparator.compare(SchemaNodeProvider.java:146)
   at java.util.TreeMap.compare(TreeMap.java:1188)
   at java.util.TreeMap.put(TreeMap.java:531)
   at java.util.TreeSet.add(TreeSet.java:255)
   at java.util.AbstractCollection.addAll(AbstractCollection.java:334)
Comment 1 dlttorezan 2011-08-27 16:15:25 UTC
Created attachment 110255 [details]
stacktrace
Comment 2 Exceptions Reporter 2011-10-07 16:40:58 UTC
This bug already has 5 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=180811
Comment 3 Exceptions Reporter 2011-10-12 12:02:30 UTC
Created attachment 111932 [details]
stacktrace
Comment 4 Jiri Rechtacek 2011-10-14 16:44:31 UTC
Added more logging to see what went wrong - core-main/rev/f34c77fbbffd
Comment 5 Exceptions Reporter 2012-02-11 19:07:01 UTC
This bug already has 20 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=180811
Comment 6 matthias42 2012-02-24 20:43:44 UTC
Created attachment 116099 [details]
Proposed patch
Comment 7 matthias42 2012-02-24 20:45:14 UTC
There are code paths, that can lead to null display names - from renderNames in SchemaNode.java (lines 146-153):

        if (schema == null) {
            name = "";
        } else {
            name = schema.getName();
        }
        if (name == null) {
            name = schema.getParent().getName();
        }

so it needs both the schema Name and the catalog name (this is the parent of the schema) to be null.

NULL-Catalogs can be created - from JDBCMetadata.java lines 171:

defaultCatalog = createJDBCCatalog(null, true, defaultSchemaName).getCatalog();

And in JDBCCatalog line 173 a JDBCSchema with a null name is created:

syntheticSchema = createJDBCSchema(null, _default, true).getSchema();

So the Comparator has to deal with null values
Comment 8 Jan Peska 2012-04-19 13:33:09 UTC
I see your point matthias, it will fix this issue, but maybe it would be better to edit renderNames to be sure that "" is returned instead of null.

Something like this:

if (schema == null) {
    name = "";
} else {
    name = schema.getName();
} 
if (name == null) {
    name = schema.getParent().getName();
}

if (name == null) {
    name = ""
}

so you don't have to check "notNull" every time you call node.getDiplayName/getName

I'm going to implement this variant but if you have any objections let me know and we can discuss it.
Comment 9 Jan Peska 2012-04-19 13:57:03 UTC
*** Bug 207828 has been marked as a duplicate of this bug. ***
Comment 10 matthias42 2012-04-19 15:20:50 UTC
Go ahead :-) - I don't see a reason not to implement it like that. It's a bit more invasive than changing the comparator, but I seriously hope noone expected null to be a valid name and build logic upon that.
Comment 11 Jan Peska 2012-04-23 07:26:15 UTC
fix: http://hg.netbeans.org/core-main/rev/f07756987b19
Comment 12 Quality Engineering 2012-04-24 10:02:03 UTC
Integrated into 'main-golden', will be available in build *201204240400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/f07756987b19
User: Jan Peska <JPESKA@netbeans.org>
Log: Issue #201380 - NullPointerException at org.netbeans.modules.db.explorer.node.SchemaNodeProvider$SchemaComparator.compare
Make sure that "" will be assigned to the name field instead of null