NoClassDefFoundError:A(错误名称:A)

发布于 2025-01-02 10:45:02 字数 1736 浏览 1 评论 0原文

在以前工作的应用程序中,我突然收到一个 NoClassDefFoundError(错误名称),这让我很困惑。我正在使用 XML 绑定框架,该框架尝试通过使用配置的类名调用 ClassLoader.loadClass() 在请求时解析绑定类。 (在这种情况下,为什么它的行为超出了我的范围。)现在我得到了 java.lang.ClassLoader.defineClass() 中刚刚提到的异常。该方法的文档称,如果参数 name 不等于指定类的二进制名称,它将抛出 NoClassDefFoundError 。我知道在这种情况下,人们期望得到表单的异常

java.lang.NoClassDefFoundError: A (wrong name: B)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:786)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:382)
    ....

,这是我实际看到的结果,但奇怪的是,在我的情况下,报告的 AB< /code> 完全一样!我尝试调试该应用程序。 JDK 源代码中的行显示:

        c = defineClass1(name, b, off, len, protectionDomain, source);

source 的值是 OK。我将字节数组 b 保存到类文件中,并使用反编译器检查它,结果又没问题了。当然,Class.forName() 始终报告相同的错误,但真正有趣的事情是,如果我在调试模式下设置 name = null我明白了:

java.lang.LinkageError: loader (instance of  com/google/gwt/dev/shell/jetty/JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension): attempted  duplicate class definition for name: "A"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:786)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:382)

现在我对此完全无能为力:( 感谢您的帮助。

有问题的类加载器是 com.google.gwt.dev.shell.jetty.JettyLauncher.WebAppContextWithReload.WebAppClassLoaderExtension如果这很重要的话。

Out of a sudden in a formerly working application, I am getting a NoClassDefFoundError (wrong name) which has puzzled me. I am using an XML binding framework which tries to resolve bound classes at request time by calling ClassLoader.loadClass() with the configured class name. (Why does it behave like that is beyond me in this case.) Now I get the exception just mentioned at java.lang.ClassLoader.defineClass(). The documentation on the method says that it will throw a NoClassDefFoundError if the parameter name is not equal to the binary name of the class specified. I am aware that in that case one expects to get an exception of the form

java.lang.NoClassDefFoundError: A (wrong name: B)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:786)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:382)
    ....

and this is the outcome I actually see, but the weird thing is that in my case the reported A and B are exactly the same! I tried to debug the app. The line in the JDK source reads:

        c = defineClass1(name, b, off, len, protectionDomain, source);

the value of source is OK. I saved the byte array b to a class file and inspected it with a decompiler and it's OK again. Of course Class.forName() reports the same error throughout, but the really funny thing is that if I set name = null in debug mode I get this beast:

java.lang.LinkageError: loader (instance of  com/google/gwt/dev/shell/jetty/JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension): attempted  duplicate class definition for name: "A"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:786)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:382)

Now I feel completely clueless on this :( I appreciate your help.

The class loader in question is com.google.gwt.dev.shell.jetty.JettyLauncher.WebAppContextWithReload.WebAppClassLoaderExtension in case that matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一瞬间的火花 2025-01-09 10:45:02

解决了。只是一个令人尴尬的大小写问题。 NoClassDefFoundError: A (wrong name: B) 中的名称 AB 实际上确实存在大小写不同。

这种情况发生在 Windows 上,因为它的文件系统不区分大小写。如果您查找名为 FooBar 的类,并且该文件夹包含文件 Foobar.class,则类加载器会打开该类文件,但发现它在内部具有不同的名称。因此例外。

Solved. Just an embarrassing capitalization issue. The names A and B in NoClassDefFoundError: A (wrong name: B) actually did differ by a capitalization.

This happens on Windows, because of its case-insensitive file system. If you look for a class named FooBar and the folder contains a file Foobar.class, the classloader opens the class file, but discovers that internally it has a different name. Hence the exception.

蘑菇王子 2025-01-09 10:45:02

检查类 A 和 B 的包声明。很可能它们在某些包内没有包声明,或者包声明不正确。

Check the package declaration for the class A and B. Chances are they are either without a package declaration inside some package or the package declaration is not correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文