Re: Exception in SAXParserFactory.newInstance with 3.0M4

From: Jerald Dawson (jdawso..rk.com)
Date: Tue Jul 01 2008 - 14:44:26 EDT

  • Next message: Scott Anderson: "RE: Exception in SAXParserFactory.newInstance with 3.0M4"

    Thanks Andrus

    I got through that exception but now am getting another one where the
    org.apache.cayenne.conn.DriverDataSource is trying to load the jdbc
    driver class. I looked in the source and see that it is similar to the
    other code we were having issues with so I'm wondering if its the same
    thing. Here is the code in question where the exception is happening:

        private static Driver loadDriver(String driverClassName) throws
    SQLException {

             Class<?> driverClass;
             try {
                 driverClass = Class.forName(driverClassName, true, Thread
                         .currentThread()
                         .getContextClassLoader());
             }
             catch (Exception ex) {
                 throw new SQLException("Can not load JDBC driver named '"
                         + driverClassName
                         + "': "
                         + ex.getMessage());
             }
    ...

    And here is the stack from the exception:
    INFO: *** Connecting: FAILURE.
    java.sql.SQLException: Can not load JDBC driver named
    'com.mysql.jdbc.Driver': com/mysql/jdbc/Driver
            at
    org
    .apache.cayenne.conn.DriverDataSource.loadDriver(DriverDataSource.java:
    62)
            at
    org
    .apache
    .cayenne
    .conn.DriverDataSource.setDriverClassName(DriverDataSource.java:256)

    As you can see, driverClass is again using getContextClassLoad from
    Thread,currentThread(). Not 100% sure that its the issue but it seems
    reasonable. Also, I have verified that the mysql jars are in my
    classpath. Also, modeler seems to see it fine and is able to access my
    database.

    jerald dawson

    On Jul 1, 2008, at 1:18 PM, Andrus Adamchik wrote:

    >> BTW, I'm using SWT if that is pertinent.
    >
    > It probably is. The ClassLoader settings are likely different.
    >
    > Anyways the code in question does look suspect. I implemented a bit
    > more paranoid version of this method (without actually knowing
    > whether null values are valid here or not). The code is checked in
    > to trunk, and you may try this cayenne-server.jar that contains the
    > fix:
    >
    > http://people.apache.org/~aadamchik/patched/cayenne-server-3.0-07012008.jar
    >
    > Andrus
    >
    >
    >
    >
    > On Jul 1, 2008, at 9:02 PM, Jerald Dawson wrote:
    >
    >> Ok, more info. I have been stepping through the code to see what is
    >> actually throwing the NPE and I've come to this code in
    >> DataSourceInfo class:
    >>
    >> public PasswordEncoding getPasswordEncoder() {
    >> PasswordEncoding encoder = null;
    >>
    >> try {
    >> encoder = (PasswordEncoding) Thread
    >> .currentThread()
    >> .getContextClassLoader()
    >> .loadClass(getPasswordEncoderClass())
    >> .newInstance();
    >> // encoder = (PasswordEncoding)
    >> // Class.forName(getPasswordEncoderClass()).newInstance();
    >> }
    >> ...
    >>
    >> Now following the code, I notice that the getContextClassLoader
    >> call returns null which seems to be the source of the NPE. Is there
    >> a reason getContextClassLoader would be returning null?
    >>
    >> BTW, I'm using SWT if that is pertinent.
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Jul 01 2008 - 14:45:22 EDT