简体   繁体   English

难道NoClassDefFoundError总是有ClassNotFoundException引起的吗?

[英]Does NoClassDefFoundError have always ClassNotFoundException in caused by?

Can I assume that every NoClassDefFoundError thrown from JDK class loading mechanism will always have ClassNotFoundException as a cause in stacktrace? 我是否可以假定从JDK类加载机制抛出的每个NoClassDefFoundError都会始终将ClassNotFoundException作为堆栈ClassNotFoundException中的原因?

Also, where actually NoClassDefFoundError is thrown and its cause is initialized to be ClassNotFoundException ? 另外,实际上在哪里抛出NoClassDefFoundError ,并将其原因初始化为ClassNotFoundException I cannot find Java code responsible for that logic. 我找不到负责该逻辑的Java代码。

This is how usually stacktraces look to me: 这是通常堆栈跟踪对我的外观:

Exception in thread "main" java.lang.NoClassDefFoundError: package/Missing
    at package.Missing(Missing.java:110)
Caused by: java.lang.ClassNotFoundException: package.Missing
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

Can I assume that every NoClassDefFoundError thrown from JDK class loading mechanism will always have ClassNotFoundException as a cause in stacktrace? 我是否可以假定从JDK类加载机制抛出的每个NoClassDefFoundError都会始终将ClassNotFoundException作为堆栈跟踪中的原因?

That's a reasonable assumption. 这是一个合理的假设。 According to the Java Virtual Machine Specification : 根据Java虚拟机规范

If the Java Virtual Machine ever attempts to load a class C during verification (§5.4.1) or resolution (§5.4.3) (but not initialization (§5.5)), and the class loader that is used to initiate loading of C throws an instance of ClassNotFoundException, then the Java Virtual Machine must throw an instance of NoClassDefFoundError whose cause is the instance of ClassNotFoundException. 如果Java虚拟机曾经在验证(第5.4.1节)或解析(第5.4.3节)(但没有初始化(第5.5节))期间尝试加载类C,则尝试启动用于加载C的类加载器抛出ClassNotFoundException的实例,则Java虚拟机必须抛出NoClassDefFoundError的实例,其原因是ClassNotFoundException的实例。

I believe the above answers your second question as well. 我相信以上内容也可以回答您的第二个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoClassDefFoundError:…由ClassNotFoundException引起 - NoClassDefFoundError: … Caused by ClassNotFoundException loadClass抛出由ClassNotFoundException引起的NoClassDefFoundError - loadClass throws NoClassDefFoundError caused by ClassNotFoundException 如何解决ClassNotFoundException引起的NoClassDefFoundError? - How to solve a NoClassDefFoundError caused by ClassNotFoundException? 类声明错误(由ClassNotFoundException引起的NoClassDefFoundError) - Class declaration bug (NoClassDefFoundError caused by ClassNotFoundException) 由java.lang.NoClassDefFoundError和ClassNotFoundException引起的错误 - Error caused by java.lang.NoClassDefFoundError and ClassNotFoundException 如果NoClassDefFoundError是由ClassNotFoundException引起的,为什么Java期望你捕获两个throwable? - If a NoClassDefFoundError is caused by a ClassNotFoundException, why does Java expect you to catch both throwables? 将 Java Web 应用程序部署到 Heroku:由 ClassNotFoundException 引起的 NoClassDefFoundError - deploying java web app to heroku: NoClassDefFoundError caused by ClassNotFoundException ClassNotFoundException 导致的线程“主”java.lang.NoClassDefFoundError 中的异常 - Exception in thread "main" java.lang.NoClassDefFoundError caused by ClassNotFoundException NoClassDefFoundError原因:java.lang.ClassNotFoundException:junit.textui.ResultPrinter - NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter 在Hive驱动程序连接线上的Hadoop中由ClassNotFoundException引起的NoClassDefFoundError? - NoClassDefFoundError caused by ClassNotFoundException in Hadoop on Hive Driver Connection line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM