Jackson + Tomcat - java.lang.VerifyError: Cannot inherit from final class

北城以北 提交于 2019-12-09 14:30:46

问题


I have a Java webservice running in Tomcat 6 which accepts JSON input. I am trying to use Jackson ObjectMapper to parse the input json. But when initializing the ObjectMapper object I am getting this error

16:08:13,616 ERROR [[jersey]] Servlet.service() for servlet jersey threw exception                                                                                                                        
java.lang.VerifyError: Cannot inherit from final class                                                                                                                                                    
    at java.lang.ClassLoader.defineClass1(Native Method)                                                                                                                                                  
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)                                                                                                                                        
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)                                                                                                                                            
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)                                                                                                                            
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2733)                                                                                                        
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1124)                                                                                                                
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)                                                                                                                
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)                                                                                                                
    at com.test.project.offline.ws.WsApiResource.updateData(WsApiResource.java:169) 
.......

At line 169 I have this ObjectMapper mapper = new ObjectMapper();

When calling com.test.project.offline.ws.WsApiResource.updateData() method locally in a unit test it works without any error.

Kindly help me in fixing this. I am using Jackson 1.8.4 and tomcat 6.

UPDATE: Fixed the issue. Problem was a different version of jackson in the dependency tree. Excluding it fixed the problem.


回答1:


I also had the same issue with Apache Lucene. I had lucene-core-3.6.0.jar and lucene-core-3.5.0.jar in my /WEB-INF/lib folder. Removing one or the other also fixed my problem. It must be a versioning issue.




回答2:


I had the same issue with Apache Solr, and it was resolved by deleting my ~/.m2 cache.

This issue was also caused by specifying the wrong version of a dependency in my pom.xml file, where another package was automatically downloading another version.

Maven really should have some sort of conflicting versions of dependency resolution scheme...




回答3:


The same for me - my ejb3 application uses jackson-all-1.9.4 - and my glassfish container (v2.1) contains a lib/jackson-asl-0.9.4.jar:

java.lang.VerifyError: Cannot inherit from final class 

Now, I have replaced jackson-all with gson.

Thanks,

Danny




回答4:


Neil has a great answer to this question. However, aside from your M2 cache, check if you're a complete DUMMY like I WAS and insure your POM doesn't include say 2 packages where the Same Final class is declared. Google API's are notorious for cross including classes in their API Jars. Insure you delete EVERYTHING you don't need!



来源:https://stackoverflow.com/questions/7766614/jackson-tomcat-java-lang-verifyerror-cannot-inherit-from-final-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!