users@glassfish.java.net

NPE loading resource located in jar's root

From: Nicolás Lichtmaier <nico.lichtmaier_at_gmail.com>
Date: Tue, 16 Jun 2009 01:29:59 -0300

I'm reposting this because, it was in an old thread, and perhaps it's being
overlooked because of that.

I'm trying to use ehcache as a cache provider in Hibernate. Ehcache loads
its configuration from an xml included in its jar, but I'm getting this
exception on application deployment:

INFO: building session factory
>> GRAVE: Exception while invoking class
>> org.glassfish.persistence.jpa.JPADeployer prepare method
>> java.lang.NullPointerException
>
>
I got this error in an old build, and I keep getting this exception in
Glassfish v3 preview:

java.lang.NullPointerException
    at
org.glassfish.web.loader.WebappClassLoader.findResourceInternalFromJars(WebappClassLoader.java:2278)
    at
org.glassfish.web.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2116)
    at
org.glassfish.web.loader.WebappClassLoader.findResource(WebappClassLoader.java:1047)
    at
org.glassfish.web.loader.WebappClassLoader.getResource(WebappClassLoader.java:1191)
    at java.lang.Class.getResource(Class.java:2074)
[...]

I've tracked it down to this (assuming I've found the right svn tag
correctly):

                                resourceFile = new File
                                    (loaderDir, jarEntry2.getName());

                                resourceFile.getParentFile().mkdirs();

What if the file is at the top level (as is the file in ehcache)?
getParentFile() will return null! In this case, there's no need to create
any directory, as the file should just be at the root. So this needs just an
"if"... am I right?

Thanks!