[英]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.