Re: NoClassDefFoundErrors - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: NoClassDefFoundErrors
Date
Msg-id 49C0BCF4.6020609@opencloud.com
Whole thread Raw
In response to Re: NoClassDefFoundErrors  (Robin Rosenberg <robin.rosenberg.lists@dewire.com>)
List pgsql-jdbc
Robin Rosenberg wrote:

> Indeed it is there. NoClassDefFoundError is ofter confused with ClassNotFoundException.
>
> NoClassDefFoundError means the class was found, but it couldn't be loaded because
> of another class was needed for the base class or interface or an exception was thrown
> in a static initializer during class loading. There might be other reasons, but those are
> the ones I know about. The problem is that these errors are very hard to debug, so I was
> hoping for a clue.

I do understand the difference between the two.

NoClassDefFoundError doesn't behave as you describe. It means, as the
name says, that the named class could not be loaded.

It's thrown as a *result* of trying to resolve the named class, perhaps
because it is named as a base class or interface during classloading of
another class, or because it's referenced by a method descriptor that
needs to be resolved (some time after classloading). In this case, the
JVM is trying to resolve a call from QueryExecutorImpl (which is loaded,
initialized, and executing) to a static method on Parser. The first time
such a method is called, the JVM attempts to load and initialize Parser
so that it can resolve the method descriptor. When it cannot find
Parser.class, a NoClassDefFoundError is thrown.

I believe the class named in the NoClassDefFoundError is always the
ultimately missing class. (So if class A exists, but initialization of A
fails because class B does not exist, then you get a
NoClassDefFoundError: B as a result of trying to resolve A)

Incidentally, exceptions in static initializers during class
initialization are reported by an ExceptionInInitializerError, *not*
NoClassDefFoundError.

I would suggest taking a hard look at how Glassfish is loading the
driver classes, sounds like it is mangling things along the way somehow.

-O

pgsql-jdbc by date:

Previous
From: Robin Rosenberg
Date:
Subject: Re: NoClassDefFoundErrors
Next
From: "Peter"
Date:
Subject: Re: Totally weird behaviour in org.postgresql.Driver