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 63745 - NPE in SchemaElementImpl.java
Summary: NPE in SchemaElementImpl.java
Status: CLOSED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: DB schema (show other bugs)
Version: 4.x
Hardware: All All
: P2 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-06 23:28 UTC by Rochelle Raccah
Modified: 2006-03-24 12:53 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rochelle Raccah 2005-09-06 23:28:46 UTC
There is a bug in SchemaElementImpl.checkReferences() that is affecting the
appserver tests when run against mysql database.
In the case of mysql database the schema name that is returned is null. 

The jdbc api documentation for DatabaseMetaData.getImportedKeys() states that
the schemaName is allowed to be null.  However, the code in checkReferences() is
not prepared to handle this and is defined as:

pkSchema = rs.getString("PKTABLE_SCHEM").trim(); //NOI18N
fkSchema = rs.getString("FKTABLE_SCHEM").trim();//NOI18N

This code throws a NPE and the schema is not being populated with the tables.
This causes the deployment of the application to fail.
Comment 1 Rochelle Raccah 2005-09-06 23:37:11 UTC
More info:
Url to JDBC docs:
<http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html#getImportedKeys(java.lang.String,%20java.lang.String,%20java.lang.String)>

The code swallows this exception by default, but is visible if you define a -D
option to the application server of the form "netbeans.debug.exceptions = true".
The code to refer to is
com/sun/forte4j/modules/dbmodel/jdbcimpl/SchemaElementImpl.initTables(ConnectionProvider
cp, LinkedList t, LinkedList v, boolean allTables) :
            } catch (Exception exc) {
                if (Boolean.getBoolean("netbeans.debug.exceptions")) // NOI18N
                    exc.printStackTrace();
            }
Comment 2 Andrei Badea 2005-09-07 12:51:25 UTC
Fixed by testing for null before calling trim(). But is the trim() call really
necessary? Note that when the schema is generated from netbeans (the if (bridge
!= null) statement on row 309 passes) the pkSchema and fkSchema are not trimmed.

Checking in SchemaElementImpl.java;
/cvs/db/model/src/org/netbeans/modules/dbschema/jdbcimpl/SchemaElementImpl.java,v
 <--  SchemaElementImpl.java
new revision: 1.4; previous revision: 1.3
done
Comment 3 Rochelle Raccah 2005-09-08 21:15:31 UTC
I filed this issue on behalf of 2 coworkers.  Here is the response I got when 
asking your trim question:
"The code doesn't trim when inside NB (bridge != null),
and trim is harmless if there is nothing to trim.
So unless they have all the tests that can proof stability,
I will keep the trim."

Thanks for the quick fix!
Comment 4 Martin Schovanek 2005-11-18 19:46:44 UTC
VERIFIED