Thread: NoClassDefFoundErrors

NoClassDefFoundErrors

From
Robin Rosenberg
Date:
Under various error conditions (and possibly otherwise) we get noclassdeffound errors instead of an SQL exception.


Caused by: java.lang.NoClassDefFoundError: org/postgresql/core/Parser
    at org.postgresql.core.v3.QueryExecutorImpl.parseQuery(QueryExecutorImpl.java:77)
    at org.postgresql.core.v3.QueryExecutorImpl.createParameterizedQuery(QueryExecutorImpl.java:55)


java.lang.NoClassDefFoundError: org/postgresql/core/Parser
    at org.postgresql.core.v3.QueryExecutorImpl.parseQuery(QueryExecutorImpl.java:77)
    at org.postgresql.core.v3.QueryExecutorImpl.createParameterizedQuery(QueryExecutorImpl.java:55)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.<init>(AbstractJdbc2Statement.java:134)
    at org.postgresql.jdbc3.AbstractJdbc3Statement.<init>(AbstractJdbc3Statement.java:41)
    at org.postgresql.jdbc4.AbstractJdbc4Statement.<init>(AbstractJdbc4Statement.java:30)
    at org.postgresql.jdbc4.Jdbc4Statement.<init>(Jdbc4Statement.java:30)
    at org.postgresql.jdbc4.Jdbc4PreparedStatement.<init>(Jdbc4PreparedStatement.java:23)
    at org.postgresql.jdbc4.Jdbc4PreparedStatement.<init>(Jdbc4PreparedStatement.java:18)
    at org.postgresql.jdbc4.Jdbc4Connection.prepareStatement(Jdbc4Connection.java:37)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareStatement(AbstractJdbc3Connection.java:266)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.prepareStatement(AbstractJdbc2Connection.java:187)

These are just a few examples. NoClassDefFoundError seems to occur in many situations and so far it has
always been related to an underlying exception of some kind. These particular cases I'm not sure about, and
cannot verify, but I suspect a bad parameter or even an SQL syntax error.

So, my question is: How do I get error handling to work? All errors don't lead to NoClassDefFoundError.

We're currently on version 8.3-603 of the driver within glassfish 2.1

-- robin

Re: NoClassDefFoundErrors

From
Oliver Jowett
Date:
Robin Rosenberg wrote:
> Under various error conditions (and possibly otherwise) we get noclassdeffound errors instead of an SQL exception.
>
> Caused by: java.lang.NoClassDefFoundError: org/postgresql/core/Parser
>     at org.postgresql.core.v3.QueryExecutorImpl.parseQuery(QueryExecutorImpl.java:77)
>     at org.postgresql.core.v3.QueryExecutorImpl.createParameterizedQuery(QueryExecutorImpl.java:55)

> We're currently on version 8.3-603 of the driver within glassfish 2.1

$ jar tvf postgresql-8.3-603.jdbc2.jar  | grep Parser.class
  2904 Thu Jan 31 03:01:38 NZDT 2008 org/postgresql/core/Parser.class

The class is there, so either you have a mangled copy of the driver jar,
or glassfish is breaking something, or you have encountered a JVM bug.

Parser is an integral part of the driver, used whenever you have a query
that contains any of these characters: '"-/$

-O

Re: NoClassDefFoundErrors

From
Robin Rosenberg
Date:
onsdag 18 mars 2009 09:45:56 skrev Oliver Jowett <oliver@opencloud.com>:
> Robin Rosenberg wrote:
> > Under various error conditions (and possibly otherwise) we get noclassdeffound errors instead of an SQL exception.
> >
> > Caused by: java.lang.NoClassDefFoundError: org/postgresql/core/Parser
> >     at org.postgresql.core.v3.QueryExecutorImpl.parseQuery(QueryExecutorImpl.java:77)
> >     at org.postgresql.core.v3.QueryExecutorImpl.createParameterizedQuery(QueryExecutorImpl.java:55)
>
> > We're currently on version 8.3-603 of the driver within glassfish 2.1
>
> $ jar tvf postgresql-8.3-603.jdbc2.jar  | grep Parser.class
>   2904 Thu Jan 31 03:01:38 NZDT 2008 org/postgresql/core/Parser.class
>
> The class is there, so either you have a mangled copy of the driver jar,
> or glassfish is breaking something, or you have encountered a JVM bug.
> Parser is an integral part of the driver, used whenever you have a query
> that contains any of these characters: '"-/$
>
> -O
>

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.

-- robin



Re: NoClassDefFoundErrors

From
Oliver Jowett
Date:
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