Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 224083 - throws proper error rather than NullPointerException when JDBC properties are not set
Summary: throws proper error rather than NullPointerException when JDBC properties are...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: Fixed in 1.0M6
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-26 08:16 EDT by Wonseok Kim CLA
Modified: 2022-06-09 10:16 EDT (History)
1 user (show)

See Also:


Attachments
patch (6.86 KB, patch)
2008-03-27 08:45 EDT, Wonseok Kim CLA
no flags Details | Diff
patch2 (4.30 KB, patch)
2008-03-28 06:49 EDT, Wonseok Kim CLA
peter.krogh: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wonseok Kim CLA 2008-03-26 08:16:49 EDT
When eclipselink.jdbc.driver property is not set correctly I got the following NPE and this is a bit misleading.

Exception in thread "main" java.lang.NullPointerException
    at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:154)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:91)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:164)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:578)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:214)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:234)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:69)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:118)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:112)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:100)

Runtime should throw proper exception telling that there is no eclipselink.jdbc.driver property.
Also JDBC-ODBC bridge driver is rarely used, so this is not definitely useful default.
Comment 1 Wonseok Kim CLA 2008-03-27 08:45:49 EDT
Created attachment 93792 [details]
patch

Patch description:
1. Checking if JDBC URL property is set properly done. This will throw proper error message rather than NPE.
2. Modify DefaultConnector not to have default driver class name (JdbcOdbc). Even if driver class name is not given, DriverManager can use already loaded drivers for the URL. Also JDBC 4.0 drivers are loaded automatically(4.0 change) if they are in the classpath. Therefore eclipselink.jdbc.driver property can be optional.
Comment 2 Wonseok Kim CLA 2008-03-28 06:49:51 EDT
Created attachment 93960 [details]
patch2

Patch description:
Considering sessions.xml and session customizer, this fix validates JDBC URL at connection creation time.
Since Connector could be set with sessions.xml or could be overrided by session customizer, just checking eclipselink.jdbc.url is not always right.
Comment 3 Tom Ware CLA 2008-04-01 09:05:37 EDT
Fix by Wonseok Kim
Reviewed by Tom Ware

Checked in Wonseok's fix.  Thanks Wonseok.

Tested with Full JPA and Full Core testing run.
These changes are exercised each time persistence units are deployed on a Login is constructed, therefore no new tests have been added.

Comment 4 Eclipse Webmaster CLA 2022-06-09 10:09:24 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:16:47 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink