2 Replies Latest reply on Aug 8, 2005 5:34 AM by Kabir Khan

    javassist.CannotCompileException: duplicate field

    Ryan McDonough Newbie

      I am experienceing weird behavior when I try to compile my aspects. I have an Introduction that will give PropertyChangeSupport to my Hibernate classes. I'm using this in a Swing app so that I can have a proper JavaBean that will work with the JGoodies Binding framework. So far, my code works using loadtime transformation through Eclipse. However, when I try to compile the classes with AopC, I get this:

      [aopc] javassist.CannotCompileException: duplicate field: _com$damnhandy$binding$aspects$ModelMixinImpl$aop$mixin
       [aopc] at javassist.bytecode.ClassFile.testExistingField(ClassFile.java:501)
       [aopc] at javassist.bytecode.ClassFile.addField(ClassFile.java:484)
       [aopc] at javassist.CtClassType.addField(CtClassType.java:836)
       [aopc] at org.jboss.aop.instrument.Instrumentor.addMixin(Instrumentor.java:240)
       [aopc] at org.jboss.aop.instrument.Instrumentor.instrumentIntroductions(Instrumentor.java:308)
       [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.java:640)
       [aopc] at org.jboss.aop.AspectManager.translate(AspectManager.java:742)
       [aopc] at org.jboss.aop.AspectManager.transform(AspectManager.java:657)
       [aopc] at org.jboss.aop.standalone.Compiler.compileFile(Compiler.java:266)
       [aopc] at org.jboss.aop.standalone.Compiler.compile(Compiler.java:199)
       [aopc] at org.jboss.aop.standalone.Compiler.main(Compiler.java:69)
       [aopc] java.lang.RuntimeException: failed to transform: com.damnhandy.binding.tutorial.Restaraunt
       [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.java:700)
       [aopc] at org.jboss.aop.AspectManager.translate(AspectManager.java:742)
       [aopc] at org.jboss.aop.AspectManager.transform(AspectManager.java:657)
       [aopc] at org.jboss.aop.standalone.Compiler.compileFile(Compiler.java:266)
       [aopc] at org.jboss.aop.standalone.Compiler.compile(Compiler.java:199)
       [aopc] at org.jboss.aop.standalone.Compiler.main(Compiler.java:69)
       [aopc] Caused by: javassist.CannotCompileException: duplicate field: _com$damnhandy$binding$aspects$ModelMixinImpl$aop$mixin
       [aopc] at javassist.bytecode.ClassFile.testExistingField(ClassFile.java:501)
       [aopc] at javassist.bytecode.ClassFile.addField(ClassFile.java:484)
       [aopc] at javassist.CtClassType.addField(CtClassType.java:836)
       [aopc] at org.jboss.aop.instrument.Instrumentor.addMixin(Instrumentor.java:240)
       [aopc] at org.jboss.aop.instrument.Instrumentor.instrumentIntroductions(Instrumentor.java:308)
       [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.java:640)
       [aopc] ... 5 more
       [aopc] Exception in thread "main" java.lang.RuntimeException: failed to transform: com.damnhandy.binding.tutorial.Restaraunt
       [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.java:700)
       [aopc] at org.jboss.aop.AspectManager.translate(AspectManager.java:742)
       [aopc] at org.jboss.aop.AspectManager.transform(AspectManager.java:657)
       [aopc] at org.jboss.aop.standalone.Compiler.compileFile(Compiler.java:266)
       [aopc] at org.jboss.aop.standalone.Compiler.compile(Compiler.java:199)
       [aopc] at org.jboss.aop.standalone.Compiler.main(Compiler.java:69)
       [aopc] Caused by: javassist.CannotCompileException: duplicate field: _com$damnhandy$binding$aspects$ModelMixinImpl$aop$mixin
       [aopc] at javassist.bytecode.ClassFile.testExistingField(ClassFile.java:501)
       [aopc] at javassist.bytecode.ClassFile.addField(ClassFile.java:484)
       [aopc] at javassist.CtClassType.addField(CtClassType.java:836)
       [aopc] at org.jboss.aop.instrument.Instrumentor.addMixin(Instrumentor.java:240)
       [aopc] at org.jboss.aop.instrument.Instrumentor.instrumentIntroductions(Instrumentor.java:308)
       [aopc] at org.jboss.aop.instrument.Instrumentor.transform(Instrumentor.java:640)


      The Restaraunt class is marked with an annotaion that pointcut picks up:

      @Observable
      public class Restaraunt {
       @TableColumn(label="Title",index = 0,editable=true)
       private String title;
       @TableColumn(label="Category",index = 1)
       private String category;
       @TableColumn(label="Location",index = 2)
       private String location;
       private String description;
       private boolean approved;
       private Date created;
       private int rating;
       /**
       *
       */
       public Restaraunt() {
      
       }
       /**
       * @return Returns the approved.
       */
       public boolean isApproved() {
       return approved;
       }
       /**
       * @param approved The approved to set.
       */
       public void setApproved(boolean approved) {
       this.approved = approved;
       }
      etc....


      And finally, here is what my jboss-aop.xml looks like:

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <aop>
      
       <bind pointcut="set(* @com.damnhandy.binding.aspects.Observable-&gt;*)">
       <interceptor class="com.damnhandy.binding.aspects.PropertyChangeInterceptor"/>
       </bind>
      
       <introduction class="@com.damnhandy.binding.aspects.Observable">
       <mixin>
       <interfaces>com.damnhandy.binding.aspects.ModelMixin</interfaces>
       <class>com.damnhandy.binding.aspects.ModelMixinImpl</class>
       <construction>new com.damnhandy.binding.aspects.ModelMixinImpl(this)</construction>
       </mixin>
       <interfaces/>
       </introduction>
      </aop>


      I'm using Java5 and JBoss AOP 1.3.1. I'd like to have all of this precompiled. Any pointers on how to fix the problem would be appreciated.

      Ryan-