java - WhiteSpaceProcessor 上的另一个奇怪的 NoClassDefFoundError

标签 java class exception structure noclassdeffounderror

这几天我一直在为一个奇怪的问题而苦苦挣扎。

只有 一个 我的网络应用程序的用户在尝试使用某些功能时遇到 NoClassDefFoundError。这是堆栈跟踪:

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)

奇怪的是 WhiteSpaceProcessor 在类路径中找不到。 我用了tattletale查看类的使用位置:

WhiteSpaceProcessor 在类路径中只存在一次: enter image description here

DatatypeConverterImpl 在类路径中只存在一次 enter image description here

我坚持这样一个事实,即在不同环境中进行的确切 war 非常完美。

工作环境:

  • Windows 机器
  • Tomcat 5.5.28
  • Java 5 (jdk1.5.0.22)

无工作环境:

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

我希望有人能指引我正确的方向。

tomcat服务器已经重启

最佳答案

您是在工作机器还是非工作机器上使用 tattletale?

也许失败的环境在 jre/lib/ext(或类似的扩展目录)中包含一些 jar 文件,并且优先使用“较低”版本?

编辑:为了更详细地了解可以抛出 NoClassDefFoundError 的情况,值得阅读 JVM spec, chapter 5 .它谈到了三种情况:

  • 根本找不到类对应的资源
  • 资源已找到,但不对应于正确的类(尽管在那种情况下我希望收到包含“错误名称”的消息)
  • 您使用的 Java 版本早于 1.2,并且类文件的主要/次要版本号不受支持。 (这种情况现在会抛出 UnsupportedClassVersionError。)

另请阅读 section 2.17.5 : 它声明如果该类处于“错误状态”(例如,先前的初始化失败,或者字节码验证失败),则将抛出 NoClassDefFoundError

现在,如果类的静态初始化程序失败,那么第一个 调用者会看到一个ExceptionInInitializerError - 但第二个 调用者会看到 NoClassDefFoundError。这是一个简短但完整的程序来证明这一点:

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);
        }
    }
}

现在,除非您的系统中的某些东西正在抑制 ExceptionInInitializerError,否则我期望NoClassDefFoundError 之前的日志中看到它,如果那是的话问题。我仍然认为更有可能您的故障系统在扩展类加载器中加载一个类,然后找不到 ShiteSpaceProcessor 类。

关于java - WhiteSpaceProcessor 上的另一个奇怪的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7769670/

相关文章:

java - 服务器未接收套接字通信

java - 从jframe加载数据到新打开的jframe

java - 当使用多个同名的类时,您应该完全限定所有用途,还是仅限定 "rare"的用途?

php - 异常处理性能

java - 如何自动化从大型数据库查询的测试? (导入或创建)

java - 如何访问其他方法中定义的变量

css - 将CSS类添加到多个元素

java - 哪个是更好的构造函数?空的还是使用字段?

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

java.lang.ClassCastException 套接字 readObject