-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ExceptionInInitializerError - Only in Eclipse - Solved!
PostPosted: Wed Jul 26, 2006 7:39 pm 
Newbie

Joined: Tue Jul 25, 2006 6:39 pm
Posts: 16
Location: Dallas, TX
This is an ordinary java project. Not a plug-in or anything else - just normal command line app.

Environment
Eclipse Version: 3.2.0
WTP 1.5
Linux 2.6.10-5-k7
ubuntu breezy
Hibernate 3.1.3
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=1.5.0_04-b05

Ok, here is the problem which I only get this issue inside of Eclipse. From the command line I get way past this issue.

In the code below I only get to new Configuration() when things go wrong. See code and excpetion below.
Code:
try
        {
            // Create the SessionFactory from hibernate.cfg.xml
            Configuration c= new Configuration();
            c.configure();
            sessionFactory = c.buildSessionFactory();
           
            logInfo("AnalyzeRawTripData Initialized");
        }
         
        catch (Throwable ex)
        {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            logException("unable to  Initialize AnalyzeRawTripData",ex);
        }


exception
Code:
java.lang.ExceptionInInitializerError
   at com.travelbahn.xgwStats.AnalyzeRawTripData.init(AnalyzeRawTripData.java:50)
   at com.travelbahn.xgwStats.XGWStatsProcess.process(XGWStatsProcess.java:53)
   at com.travelbahn.xgwStats.XGWStatsProcess.main(XGWStatsProcess.java:196)
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException) (Caused by org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException))
   at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
   at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
   at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
   at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
   at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:116)
   ... 3 more
Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException)
   at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
   at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
   ... 7 more
Caused by: java.lang.NullPointerException
   at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)
   ... 8 more


I've traced this down into the bowls of common-logging api into org.apache.commons.logging.impl.LogFactory in the method getLogConstructor() (see below). What happens in the line logInterface = this.getClass().getClassLoader().loadClass... the first call this.getClass() returns null and thus as the stack unwraps you get the exception above.

So why does this.getClass() return null? Only thing in the code and java docs says that some JVM's will return null (lots of help there).

Code:
protected Constructor getLogConstructor()
        throws LogConfigurationException {

        // Return the previously identified Constructor (if any)
        if (logConstructor != null) {
            return logConstructor;
        }

        String logClassName = getLogClassName();

        // Attempt to load the Log implementation class
        Class logClass = null;
        Class logInterface = null;
        try {
            logInterface = this.getClass().getClassLoader().loadClass  [b]<-- this.getClass returns null[/b]
                (LOG_INTERFACE);
            logClass = loadClass(logClassName);
            if (logClass == null) {
                throw new LogConfigurationException
                    ("No suitable Log implementation for " + logClassName);
            }
            if (!logInterface.isAssignableFrom(logClass)) {
                Class interfaces[] = logClass.getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    if (LOG_INTERFACE.equals(interfaces[i].getName())) {
                        throw new LogConfigurationException
                            ("Invalid class loader hierarchy.  " +
                             "You have more than one version of '" +
                             LOG_INTERFACE + "' visible, which is " +
                             "not allowed.");
                    }
                }
                throw new LogConfigurationException
                    ("Class " + logClassName + " does not implement '" +
                     LOG_INTERFACE + "'.");
            }
        } catch (Throwable t) {
            throw new LogConfigurationException(t);
        }

        // Identify the <code>setLogFactory</code> method (if there is one)
        try {
            logMethod = logClass.getMethod("setLogFactory",
                                           logMethodSignature);
        } catch (Throwable t) {
            logMethod = null;
        }

        // Identify the corresponding constructor to be used
        try {
            logConstructor = logClass.getConstructor(logConstructorSignature);
            return (logConstructor);
        } catch (Throwable t) {
            throw new LogConfigurationException
                ("No suitable Log constructor " +
                 logConstructorSignature+ " for " + logClassName, t);
        }
    }


Let me also say this only happens in Eclipse. Using a small script to run the app from the command line seems to work just fine.

I've built other apps in Eclipse which do straight JDBC and everything is good there. My only issue is with running Eclipse and Hibernate together. Odd thing is I can use the Hibernate tools (for the most part) with little trouble but can't run the code.

One other piece of info is if I put the following just before the contructor; works but it still fails in the hibernate constructor.
Code:
Class.forName("org.apache.commons.logging.LogFactory");


Been fighting this thing for a week and can't seem to get anywhere on what is causing the issue?


Last edited by gxwilson on Thu Jul 27, 2006 7:40 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 7:40 pm 
Newbie

Joined: Tue Jul 25, 2006 6:39 pm
Posts: 16
Location: Dallas, TX
Solved - see http://forum.hibernate.org/viewtopic.php?t=962498&highlight=


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.