Reputation: 49639
I'm having an issue with my project and after some testing I don't think it's source related. Even when going back to a previously working revision I still get an error when I try to deploy to Tomcat.
The error is a org.springframework.beans.factory.BeanDefinitionStoreException
caused by a java.lang.ClassFormatError
with the message Truncated class file.
I've started narrowing down the issue by remove Eclipse from equation but even when using a maven command line build and deploying directly to my tomcat instance I still get the same issue. Googling for the error came up with people suggesting clearing the tomcat work and temp directory, which I did with no luck.
I know this isn't a lot of information, but assuming the issue isn't with my code, which changes to my system could cause this issue to suddenly manifest?
Stack trace
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [beans.xml]; nested exception is java.lang.ClassFormatError: Truncated class file
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:239)
... 54 more
Caused by: java.lang.ClassFormatError: Truncated class file
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:1847)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.apache.xbean.spring.context.v2c.XBeanQNameHelper.loadClass(XBeanQNameHelper.java:102)
at org.apache.xbean.spring.context.v2c.XBeanQNameHelper.getBeanInfo(XBeanQNameHelper.java:72)
at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.getPropertyDescriptor(XBeanNamespaceHandler.java:581)
at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.addAttributeProperties(XBeanNamespaceHandler.java:333)
at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parseBeanFromExtensionElement(XBeanNamespaceHandler.java:225)
at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parseBeanFromExtensionElement(XBeanNamespaceHandler.java:276)
at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:156)
at org.apache.xbean.spring.context.v2.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:49)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1419)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 59 more
Upvotes: 4
Views: 17391
Reputation: 49639
This question is pretty old at this point but I remember the situation pretty clearly despite it being 4 years ago.
The underlaying cause of this issue in this case was that my disk was getting corrupted due to a firmware issue. I've had similar things happen to me in other situations due to failing memory or disk failures for other reasons.
The reason I am posting this after so long is that I see a lot of responses that have localized solutions to this issue. YMMV and corruption can happen without full blown disk or memory failure but consider this answer a PSA.
If you are encountering this issue or similar issues, take some time to check the integrity of your disk and RAM. These types of issues may just be the tip of the iceberg.
Upvotes: 0
Reputation: 1964
Yes, Last file class I am working on that may causing issue to run application I uncalled that class file from main class and now working fine.
Upvotes: 0
Reputation: 41
The problem is some where your class file / jar containing the class file is is corrupted. Find the package for which class you are getting this error. If its your file, clean and rebuild, it should solve problem. If the problem is because of any external package, re-down load and it should solve your problem.
If you are using maven delete your local m2 repository and rebuild.
Upvotes: 0
Reputation: 51
Such errors can occur if the class you are working on gets corrupted. If the issue is with a class you are working on, just do a clean build and the issue would get resolved.
If the error is because of a third party JAR/ API, re-downloading the same will in most cases solve the issue.
If you are using a build tool/ framework, then delete the existing repository and re-run the tool.
Upvotes: 0
Reputation: 4373
I deleted the target folder and did clean compile and now all is well.
Upvotes: 0
Reputation: 225
If you are running JSPs simply go into your TOMCAT_HOME/work/Catalina/localhost/ directory, look for the name of your webapp, cd into that and go all the way down the directory tree from there until you find the JSP class files.. sudo rm -f * and try again.
No need to reinstall everything or rebuild anything, nothing you did was corrupt.. sometimes the compiler gets confused.
Upvotes: 4
Reputation: 1
I tried a lot to come out of this issue, but finally i found it, it is not the problem of corrupted .class file. this corrupted .class files stored in your local server(Tomcat7, etc...). so
be happy coding.
Upvotes: 0
Reputation: 1539
Had a problam exactly like this. The same exception would be thrown on all web applications, and they can not all be corrupted. Also tried to remove and re-deploy the wars, check the disk for bad sectors etc. Finally fixed by removing and re-installinng tomcat7.
apt-get purge tomcat7
apt-get install tomcat7
Root cause remains a mystery.
Upvotes: 0
Reputation: 25150
It looks like one of the class files is corrupted, but the problem is finding which one.
One way to debug this is to use eclipse's break on exception feature. Start tomcat so that it waits for a debugger to attach before running, then break on the java.lang.ClassFormatError being thrown, and look around the local variables and the stack in eclipse to see which class is failing to load.
Upvotes: 5