-->
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.  [ 1 post ] 
Author Message
 Post subject: getClassLoader() may return null
PostPosted: Mon Nov 10, 2014 11:03 am 
Newbie

Joined: Mon Nov 10, 2014 10:55 am
Posts: 1
Thank you for the great persistence implementation! Unfortunately, I found a bug. I found the reason, so maybe, somebody can fix this, if you agree, that it really is a bug.

In org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl (hibernate 4.3.1) in line 95 (source code repository also contains this line: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java#L93) the class loader of ClassLoaderServiceImpl is added to the list of available class loaders, which is later used for resource loading (ie finding the hibernate.cfg.xml file).
Code:
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );


Later, in line 188 (source code repository line 186 https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java#L186) we have the following:
Code:
         for ( ClassLoader classLoader : individualClassLoaders ) {
            final Enumeration<URL> urls = classLoader.getResources( name );
            while ( urls.hasMoreElements() ) {
               resourceUrls.add( urls.nextElement() );
            }
         }


This throws a null pointer exception for the Eclipse class loader (obviously not the standard class loader, when running a plain Java application from the Eclipse IDE). If my application is started from Eclipse, java.lang.Class.getClassLoader() returns null according to the Javadoc of the class Class:
Quote:
getClassLoader()

Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.


I also asked the Eclipse guys to return the classloader instead of null. However, the javadoc clearly specifies, that the getClassLoader could return null, and this should be checked for before calling getResources() on it, or -- probably even better -- before adding it to the list of class loaders (however, it may be necessary, to get the bootstrap class loader using another way and adding this one too?).

Thank you again for reading my comments and for your great forum,

Stephan


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

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.