javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory; " the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature org.apache.jasper.servlet.JspServlet.service(JspServlet.java:343) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature org.apache.jsp.index_jsp._jspInit(index_jsp.java:31) org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49) org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
// Constraints on class loaders. The details of the algorithm can be // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is // that the system dictionary needs to maintain a set of contraints that // must be satisfied by all classes in the dictionary. // if defining is true, then LinkageError if already in systemDictionary // if initiating loader, then ok if InstanceKlass matches existing entry
Klass* check = find_class(d_index, d_hash, name, loader_data); if (check != (Klass*)NULL) { // if different InstanceKlass - duplicate class definition, // else - ok, class loaded by a different thread in parallel, // we should only have found it if it was done loading and ok to use // system dictionary only holds instance classes, placeholders // also holds array classes // 如果是不同的 InstanceKlass - 表示类的重复定义, // 否则 - 没问题,类是由不同的线程并行加载的, // 我们只应该找到它,如果它已经完成加载并且可以使用。 // 系统字典只存储实例类, // 占位符还存储数组类。
assert(check->oop_is_instance(), "noninstance in systemdictionary"); if ((defining == true) || (k() != check)) { linkage_error = "loader (instance of %s): attempted duplicate class " "definition for name: \"%s\""; } else { return; } }
if (linkage_error == NULL) { if (constraints()->check_or_update(k, class_loader, name) == false) { linkage_error = "loader constraint violation: loader (instance of %s)" " previously initiated loading for a different type with name \"%s\""; } } }
// Throw error now if needed (cannot throw while holding // SystemDictionary_lock because of rank ordering)
son org.example.HelloImplSon start, son org.example.HelloInterface start, son java.lang.Object start, parent java.lang.Object start, son java.lang.Throwable start, objc[79363]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/bin/java (0x10235b4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10aa884e0). One of the two will be used. Which one is undefined. java.lang.Object java.lang.Object son org.example.HelloInterface end, org.example.SonClassLoader@266474c2 son org.example.HelloImplSon end, org.example.SonClassLoader@266474c2 java.lang.Throwable java.lang.Throwable parent java.lang.Throwable start, son java.lang.Error start, java.lang.Error parent java.lang.Error start, java.lang.Error son org.example.HelloModel start, son org.example.HelloModel end, org.example.SonClassLoader@266474c2 son org.example.Delegate start, org.example.Delegate parent org.example.Delegate start, parent java.lang.Object start, parent org.example.HelloInterface start, java.lang.Object parent org.example.Delegate end, org.example.ParentClassLoader@7440e464 java.lang.LinkageError: loader constraint violation: loader (instance of org/example/ParentClassLoader) previously initiated loading for a different type with name "org/example/HelloInterface" at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at org.example.MyClassLoader.loadClass(MyClassLoader.java:76) at org.example.HelloImplSon.hello(HelloImplSon.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.example.Main.main(Main.java:18)