Announcement Announcement Module
Collapse
No announcement yet.
java.lang.ClassFormatError: Duplicate method name&signature in class file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.ClassFormatError: Duplicate method name&signature in class file

    Hello,

    I have a very weird behavior with a Roo ( 1.2.2.RELEASE [rev 7d75659]) application when I try to start it in a TC server (v2.7 in a STS 3.1.0.RELEASE using JDK 1.6.0_26)

    Among other entities, I have an abstract base class for SINGLE TABLE inheritance hierarchy:

    Code:
    entity jpa --class ~.core.Base --abstract --identifierColumn c_id --table t_unique --inheritanceType SINGLE_TABLE
    field string --fieldName name --notNull --sizeMax 20 --column c_name
    ...
    It has three childs. Their unit tests work with no issues.

    Code:
    entity jpa --class ~.core.ab.Ret --extends ~.core.Base --testAutomatically 
    entity jpa --class ~.core.cd.Rep --extends ~.core.Base --testAutomatically 
    entity jpa --class ~.core.ef.SegRet --extends ~.core.Base --testAutomatically
    But once the application is deployed in the TC server, it starts with an error:

    ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    nested exception is java.lang.ClassFormatError: Duplicate method name&signature in class file com/malsolo/app/core/Base
    While debugging, I've found that the error is due to the third child, that is the first entity to be loaded, when it's been scanning, the class loader can't load its abstract parent due to the "Duplicate method name&signature" error.

    If I remove this very entity, the application works without problems.

    Has anyone had a experience like that?

    NOTES:

    I'm using DiscriminatorFormula:

    Code:
    @DiscriminatorFormula(Base.DISCRIMINATOR_FORMULA)
    public abstract class Base {
    
        public static final String DISCRIMINATOR_FORMULA = "...";
    With

    Code:
    @DiscriminatorValue(SegRet.DISCRIMINATOR_VALUE)
    public class SegRet extends Base {
    	
        public static final String DISCRIMINATOR_VALUE = "SEG_RET";
    
        public static final String DISCRIMINATOR_FORMULA = "...";
    And so on.

    The problem is located in org.hibernate.ejb.packaging.NativeScanner.getClass esInJar, when it tries to load one by one the scanned classes:

    Code:
    		Set<Class<?>> classes = ...
    		for ( Entry entry : classesEntry ) {
    			try {
    				classes.add( ReflectHelper.classForName( entry.getName() ) );// <- HERE
    			}
    			catch ( ClassNotFoundException e ) {
    				...
    			}
    		}
    		return classes;
    The call to org.hibernate.internal.util.ReflectHelper.classFor Name(String) fails:

    Code:
    	public static Class classForName(String name) throws ClassNotFoundException {
    		try {
    			ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    			if ( contextClassLoader != null ) {
    				return contextClassLoader.loadClass(name);//<- HERE
    But at the end it delegates to native code and I can't see any further details regarding the duplicate name or method

    Almost Full stack trace:

    ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'emf' defined in URL [jar:file:/C:/.../springsource-3.1.0.RELEASE-e3.8/vfabric-tc-server-developer-2.7.2.RELEASE/base_bio-ssl_insight/wtpwebapps/app-web/WEB-INF/lib/app-0.1.0.BUILD-SNAPSHOT.jar!/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.ClassFormatError: Duplicate method name&signature in class file com/malsolo/app/core/Base
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplic ationContext.registerBeanPostProcessors(AbstractAp plicationContext.java:734)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:457)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:383)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 111)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4791)
    at org.apache.catalina.core.StandardContext.startInte rnal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(Lifec ycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:618)
    at org.apache.catalina.startup.HostConfig.deployDescr iptor(HostConfig.java:650)
    at org.apache.catalina.startup.HostConfig$DeployDescr iptor.run(HostConfig.java:1582)
    at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: ...
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1455)
    at
    ... more
    Caused by: ...
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :616)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:141)
    at org.apache.catalina.loader.WebappClassLoader.findC lassInternal(WebappClassLoader.java:2904)
    at org.apache.catalina.loader.WebappClassLoader.findC lass(WebappClassLoader.java:1173)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1681)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1559)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :616)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:141)
    at org.apache.catalina.loader.WebappClassLoader.findC lassInternal(WebappClassLoader.java:2904)
    at org.apache.catalina.loader.WebappClassLoader.findC lass(WebappClassLoader.java:1173)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1681)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1559)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.hibernate.internal.util.ReflectHelper.classFor Name(ReflectHelper.java:192)
    at org.hibernate.ejb.packaging.NativeScanner.getClass esInJar(NativeScanner.java:136)
    at org.hibernate.ejb.Ejb3Configuration.addScannedEntr ies(Ejb3Configuration.java:485)
    at org.hibernate.ejb.Ejb3Configuration.scanForClasses (Ejb3Configuration.java:852)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3 Configuration.java:597)
    at org.hibernate.ejb.HibernatePersistence.createConta inerEntityManagerFactory(HibernatePersistence.java :73)
    at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:287)
    at org.springframework.orm.jpa.Abst27-dic-2012 7:53:26 org.apache.catalina.core.StandardContext listenerStart

  • #2
    I ran into this when I tried to upgrade to a newer version of aspectj-maven-plugin. I've been stuck on 1.0 forever because of early roo problems, where I'm also tied to 1.1.5 due to issues upgrading to 1.2.X. With the aspectj-maven-plugin version 1.4, I started running into the
    java.lang.ClassFormatError: Duplicate method name&signature in class file
    error. I can't say whether the cause is exactly the same as yours as I have not traced it to that level. My problem was in unit tests, not the runtime app.

    What was odd about this behavior is that it wasn't consistent across all build machines. Only some started failing with the aspectj plugin update.

    Comment


    • #3
      Thank you very much for your answer, Bruce.

      It's very weird, indeed, because it's true that the error depends on the environment: the unit tests don't fail, but the TC server doesn't start.

      I haven't found the cause of the problem, but I've tried some kind of shameful solution: I've removed the third child and I've written it again in another package.

      BTW, I changed the actual names for confidentiality reasons, but I didn't choose the appropriate fake names.

      Just in case you find this POST useful, the next names are more accurate:

      ~.core.Exchange; //Abstract parent class
      ~.core.at.Attempt; // First concrete entity child
      ~.core.re.Rejection; // Second concrete entity child

      These hierarchy has no problems, but, when added:

      ~.core.at2.SecondAttempt; // Third concrete entity child. It's actually the first entity of the hierarchy that TC server tries to load (after a few other entities, that are succesfully loaded)

      What have I done? I'm not very proud, but it works (yes, I know, it's sheer coincidence)

      I removed:
      ~.core.at2.SecondAttempt;

      And I copied its content into the same class located in another package:

      ~.core.sa.SecondAttempt;

      What I find more annoying is that I've spent several years struggling with the WebSphere class loaders, and I couldn't imagine that I will face similar issues with Tomcat or related.

      Thanks again.

      Comment


      • #4
        I will definitely second the weirdness here as in my case changing the path name to my build tree causes the problem to go away or reappear. It shows un in branch builds and goes away if rename the branch. Changes in maven plugin versions that appear to fix the problem in some trees cause it to start happening in others.
        It's like the proverbial nailing jello to the ceiling.

        Comment


        • #5
          Indeed.

          I wish someone from Springsource could shed light on this issue.

          Comment


          • #6
            Sorry to resurrect this thread, I came across it while researching something else.

            This answer may be more relevant to Bruce, as I ran into this problem going from 1.1.5 to 1.2.x a while ago.

            Check your source tree for lingering files like this:

            ClassName_Roo_Entity.aj

            Roo switches from @RooEntity to @RooJpaActiveRecord, producing new ITDs like so:

            ClassName_Roo_Jpa_ActiveRecord.aj
            ClassName_Roo_Jpa_Entity.aj

            However, in my case, it didn't remove the old ClassName_Roo_Entity.aj and thus there were two ITDs trying to add the same methods. Go through and manually delete ClassName_Roo_Entity.aj and the exception should go away.

            HTH

            -Luke

            Comment


            • #7
              Thanks for your answer, Luke.

              It wasn't the problem, though.

              If you have the two aspect files (_Entity and _ActiveRecord), the you'll have duplicated the @Entity annotation for the java class, and the code won't compile.

              In my case, the code had no compilation errors, and the unit tests seemed to work, but the server failed on start up.

              After my correction, the error never appeared again, so I still don't know what happened.

              However, I appreciate your help.

              Comment


              • #8
                I realize you've solved your problem now, but I'll post something else for others to try. I was getting "Duplicate method name&signature" on a @MappedSuperclass (unrelated to my earlier post). This only happened in STS (3.1.0 w/ tc server 2.7.2). I could deploy to the stage server fine (plain old tomcat7). I found that disabling Spring Insight allowed the server to start within STS. Not ideal, as Insight is a useful tool, but at least I could work locally.

                -Luke

                Comment


                • #9
                  Actually I didn't solve anything. In fact, the real problem is that all was working fine until suddenly the server didn't start and I can't figure out why. My only workaround was a renaming of a package (that has no sense, at least theorically)

                  Regarding insight, I had problems in earlier versions, so I also deactivate it when something doesn't work in the web application server and I don't know why.

                  I wish someone find out the real reason of the Duplicate method name & signature error, so thanks, Luke, for resurrecting the thread.

                  Comment

                  Working...
                  X