users@glassfish.java.net

Re: NullPointerException in v3 prelude while loading a resource.

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Thu, 18 Jun 2009 16:31:36 -0700

On 06/12/09 10:38 PM, Nicolás Lichtmaier wrote:
>
> On Mon, May 18, 2009 at 3:03 PM, Jan Luehe <Jan.Luehe_at_sun.com
> <mailto:Jan.Luehe_at_sun.com>> wrote:
>
> On 05/16/09 09:44 AM, Nicolás Lichtmaier wrote:
>
> 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
>
>
> Can you try with a more recent GlassFish v3 build and see if you can
> reproduce the NPE?
>
> Line 2230 of WebappClassLoader.java currently reads like this:
>
> ResourceEntry entry = null;
>
> which will never cause any NPE.
>
>
> I've tried now enabling Hibernate's 2nd level cache again, this time
> with Glassfish v3 preview. I'm getting the same exception (with
> different line numbers):
>
> 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?

A null check won't hurt, but I still don't understand how
getParentFile() could ever return
"null" for you.

The WebappClassLoader code snippet you are referring to enumerates the
static resources
of the JAR files in WEB-INF/lib, and extracts them to the file system.

For example, if you deploy a web application 123.war which contains a
JAR file
WEB-INF/lib/test.jar which in turn contains a top-level resource "abc",
then a classloader
request for this resource will cause the entries of WEB-INF/lib/test.jar
to be exploded to this
location in your domain:

  generated/jsp/123/loader/

In other words, the top-level resource "abc" will be written to:

  generated/jsp/123/loader/abc

It will always have a parent directory (in this case:
generated/jsp/123/loader).

Can you elaborate your scenario to help me understand why you are
getting an NPE?
Can you try with the trunk build, just to make sure you have the correct
line number where
the NPE occurs?

Thanks,

Jan
> Thanks!