1

I'm strugelling with an odd problem for days now.

Only one of the users of my webapp get an NoClassDefFoundError when trying to use some functionallity. This is the stacktrace:

java.lang.NoClassDefFoundError: com/sun/xml/bind/WhiteSpaceProcessor
    at com.sun.xml.bind.DatatypeConverterImpl._parseInt(DatatypeConverterImpl.java:105)
    at com.foo.bar.webservice.generated.GetLoginsRequest_JaxbXducedAccessor_panelId.parse(TransducedAccessor_field_Integer.java:32)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:166)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:406)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:384)
    at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:35)
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:101)
    at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:224)
    at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:107)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:289)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:272)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:106)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:424)

On a strange way WhiteSpaceProcessor can't be found while it is on the classpath. I used tattletale to look at the possitions of the usage of the classes:

WhiteSpaceProcessor only exist once on the classpath: enter image description here

DatatypeConverterImpl only exist once on the classpath enter image description here

I'm stuck on the fact that the exact war on a different environment is working perfect.

working environment:

  • Windows machine
  • Tomcat 5.5.28
  • Java 5 (jdk1.5.0.22)

none working environment:

  • Linux machine
  • Tomcat 5.5.??
  • Java 5 (jdk1.5.0.22)

I hope somebody can sent me in the right direction.

tomcat server is already restarted

Michel
  • 9,220
  • 13
  • 44
  • 59

2 Answers2

2

Did you use tattletale on the working or non-working machine?

Perhaps the failing environment contains some jar file in jre/lib/ext (or a similar extensions directory), and that's being used in preference to a "lower down" version?

EDIT: Just to go into a bit more detail about the situations in which NoClassDefFoundError can be thrown, it's worth reading the JVM spec, chapter 5. It talks about three situations:

  • The resource corresponding to the class can't be found at all
  • The resource is found, but doesn't correspond to the right class (although in that case I'd expect a message including "wrong name")
  • You're using a version of Java earlier than 1.2, and the class file has an unsupported major/minor version number. (This situation now throws UnsupportedClassVersionError.)

Also read section 2.17.5: it states that if the class is in an "erroneous state" (e.g. previously initialization failed, or there was a bytecode verification failure) then NoClassDefFoundError will be thrown.

Now, if the static initializer of the class fails then the first caller sees an ExceptionInInitializerError - but the second caller sees NoClassDefFoundError. Here's a short but complete program to demontrate this:

class Foo {
    static {
        if (true) {
            throw new RuntimeException();
        }
    }

    static void foo() {
    }
}

public class Test {

    public static void main(String[] args) {
        try {
            Foo.foo();
        } catch (Throwable t) {
            System.out.println("First exception: " + t);
        }
        try {
            Foo.foo();
        } catch (Throwable t) {
            System.out.println("Second exception: " + t);
        }
    }
}

Now unless something in your system is suppressing the ExceptionInInitializerError, I'd expect to see that in the log before NoClassDefFoundError if that were the problem. I still think it's more likely that your failing system is loading one class in an extension classloader which then can't find the ShiteSpaceProcessor class.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I used it on the working environment because I didn't have enough rights on the non-working machine. But if I understand it correct there must be an jar somewhere on the path that also represents the `com/sun/xml/bind/WhiteSpaceProcessor` class? – Michel Oct 15 '11 at 09:36
  • 1
    @michel: It's more likely that there's another jar file earlier in the classpath which contains DatatypeConverterImpl but *doesn't* contain WhiteSpaceProcessor. – Jon Skeet Oct 15 '11 at 09:39
  • That makes sense! I'm going to look for a certain jar using jarvana and jarfinder – Michel Oct 15 '11 at 10:06
2

NoClassDefFoundError does not mean that the class file cannot be found in the classpath. It means that the class cannot be loaded. This is generally due to an error during initialization, or, more often, a version mismatch in JAR files on which the class depends.

Eg, you probably compiled against XYZ package version 1.2 and your user has XYZ version 1.1 installed.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
  • It certainly *can* mean that the class file cannot be found in the classpath. For example, I just compiled a program using Joda Time (with it on the class path) then tried to run it without it being on the class path, and that's the error I got... – Jon Skeet Oct 15 '11 at 09:41
  • I'm betting, if you look at the exception message, you got that error on a class that WAS found, and the failure occurred because the found class could not be "loaded" due to the missing reference. – Hot Licks Oct 15 '11 at 12:07
  • That's possible, but I still think your post is misleading stating that the exception "does not" mean that the class file cannot be found on the classpath. It *might* not mean that, but it might. – Jon Skeet Oct 15 '11 at 12:56
  • It means what it means, which is that the named class was found but cannot be loaded. There are, in total, about a half-dozen causes of the error, including having the class misnamed. – Hot Licks Oct 15 '11 at 13:06
  • The interesting thing is that the documentation actually explicitly states "... and no definition of the class could be found". I've just tried writing a class which explicitly fails in the static initializer, and received an `ExceptionInInitializerError` instead of `NoClassDefFoundError`. – Jon Skeet Oct 15 '11 at 13:45
  • It depends on where it fails in static initialization. There's more to it than simply running the explicit initializer code. And "no definition of the class could be found" means that, after the .class file was located, the loader could not produce a valid loaded class from it. – Hot Licks Oct 15 '11 at 17:24
  • Giving it a completely duff file results in a `ClassFormatError`. Can you show a concrete, complete example of a situation where the class resource can be found, but you get a `NoClassDefFoundError` when some other code tries to use it at execution time? – Jon Skeet Oct 15 '11 at 17:35
  • I could, but this is getting tedious. How many JVMs have you nursed through the Sun JCK? How many bytecode interpreters have you written? How many bytecode verifiers have you written? – Hot Licks Oct 15 '11 at 18:18
  • None - but I still suspect my answer is more likely to end up leading to the solution :) I dare say you're correct that there can be alternative causes to the error than the class can't be found, but a concrete example would be interesting to see, as everything I've tried so far has led to different exceptions. (As an aside, appeals to authority like your previous comment usually aren't nearly as helpful to *anyone* as concrete information.) – Jon Skeet Oct 15 '11 at 18:21
  • 1
    I've now looked up the JVM spec on this topic, and have edited my answer to contain the sort of short but complete program I was suggesting you might provide. I still think the most likely problem is that the class really can't be found though :) – Jon Skeet Oct 15 '11 at 18:42