0 Replies Latest reply on Feb 6, 2006 5:42 AM by Adrian Brock

    Fix to EnclosingMethodAttribute

    Adrian Brock Master

      I was seeing an issue where an EnclosingAttribute didn't have a method index (it was zero).
      This caused the compact/clone to fail.

      Ths was code generated with JDK5 and it looked it was recording the enclosing
      class rather than an method

      public class MyClass
      {
       public class InnerClass
       {
       }
      }
      


      I fixed the problem by adding a new constructor that copeis the attribute retaining
      the null index.

      User: adrian
       Date: 06/02/06 05:02:34
      
       Modified: src/main/javassist/bytecode EnclosingMethodAttribute.java
       Log:
       Compacting/clone has a problem when the method index is zero.
       This looks like an inner class trying to describe its outer class rather
       than a method.
      
       Revision Changes Path
       1.4 +20 -0 javassist/src/main/javassist/bytecode/EnclosingMethodAttribute.java
      
       (In the diff below, changes in quantity of whitespace are not shown.)
      
       Index: EnclosingMethodAttribute.java
       ===================================================================
       RCS file: /cvsroot/jboss/javassist/src/main/javassist/bytecode/EnclosingMethodAttribute.java,v
       retrieving revision 1.3
       retrieving revision 1.4
       diff -u -b -r1.3 -r1.4
       --- EnclosingMethodAttribute.java 11 Jan 2006 06:45:56 -0000 1.3
       +++ EnclosingMethodAttribute.java 6 Feb 2006 10:02:34 -0000 1.4
       @@ -56,6 +56,24 @@
       }
      
       /**
       + * Constructs an EnclosingMethod attribute.
       + *
       + * @param cp a constant pool table.
       + * @param className the name of the innermost enclosing class.
       + */
       + public EnclosingMethodAttribute(ConstPool cp, String className) {
       + super(cp, tag);
       + int ci = cp.addClassInfo(className);
       + int ni = 0;
       + byte[] bvalue = new byte[4];
       + bvalue[0] = (byte)(ci >>> 8);
       + bvalue[1] = (byte)ci;
       + bvalue[2] = (byte)(ni >>> 8);
       + bvalue[3] = (byte)ni;
       + set(bvalue);
       + }
       +
       + /**
       * Returns the value of <code>class_index</code>.
       */
       public int classIndex() {
       @@ -105,6 +123,8 @@
       * class names.
       */
       public AttributeInfo copy(ConstPool newCp, Map classnames) {
       + if (methodIndex() == 0)
       + return new EnclosingMethodAttribute(newCp, className());
       return new EnclosingMethodAttribute(newCp, className(),
       methodName(), methodDescriptor());
       }