4

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
James McMahon
  • 48,506
  • 64
  • 207
  • 283

9 Answers9

5

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.

Community
  • 1
  • 1
sbridges
  • 24,960
  • 4
  • 64
  • 71
  • Thanks, I will give that a try tomorrow. Why would a class file consistently get corrupted even when doing full builds? Maybe something is up with my artifactory. – James McMahon Feb 19 '12 at 06:10
  • it could be as simple as bad sectors on ur drive...or could be more complex...but it is difficult to pin point... – havexz Feb 19 '12 at 06:15
  • 1
    Yeah my activemq class files in my local maven repo somehow got corrupted. Deleting those files from the repo fixed the issue. Thanks. – James McMahon Feb 19 '12 at 15:15
  • We have this problem with one application only. Locally everything works, but when we deploy to other zones we get this error. Sometimes server restart fixes this, other times it causes this. Probably linked to Tomcat war unpacking somehow? –  Mar 14 '17 at 07:28
4

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.

JoGotta
  • 215
  • 2
  • 13
0

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.

Hannes R.
  • 1,379
  • 16
  • 23
0

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

  1. please remove your server.
  2. clean your project (in menu bar : Prject --> clean)
  3. add it again to your eclipse.
  4. project clean and install with maven.
  5. run your project.

be happy coding.

0

I deleted the target folder and did clean compile and now all is well.

ABC
  • 4,263
  • 10
  • 45
  • 72
0

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.

0

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.

0

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.

A.Aleem11
  • 1,844
  • 17
  • 12
0

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.

James McMahon
  • 48,506
  • 64
  • 207
  • 283