You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-dev@jakarta.apache.org by bu...@apache.org on 2008/06/16 22:14:00 UTC

DO NOT REPLY [Bug 45217] New: L

https://issues.apache.org/bugzilla/show_bug.cgi?id=45217

           Summary: L
           Product: BCEL
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Main
        AssignedTo: bcel-dev@jakarta.apache.org
        ReportedBy: mj.wilson.uk@googlemail.com





-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 45217] MethodGen: LocalVariableTableGen issues

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45217


Matthew Wilson <mj...@googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|L                           |MethodGen:
                   |                            |LocalVariableTableGen issues




--- Comment #1 from Matthew Wilson <mj...@googlemail.com>  2008-06-16 13:15:52 PST ---
MethodGen mistakenly fills in LocalVariableTableGen from both
LocalVariableTable and LocalVariableTypeTable.  In parsing
LocalVariableTypeTable, it incorrectly reads the signatures with generics.  As
a result, the LocalVariableTable is corrupted.

Here is an example:

public class VariableTableBug
{

   public String getFirstItem( final List< String > list )
   {
      int index = 0;
      String result = list.get( index );
      return result;
   }

   public static void main( final String[] args ) throws Exception
   {
      // find the resource that is our class
      Class< VariableTableBug > clazz = VariableTableBug.class;
      String resource = clazz.getName().replace( '.', '/' ) + ".class";

      // load it using BCEL
      JavaClass javaClass = new ClassParser(
clazz.getClassLoader().getResourceAsStream( resource ),
                                             resource ).parse();

      // convert everything to a ClassGen
      ClassGen classGen = new ClassGen( javaClass );

      // find them getFirstItem method
      Method getFirstItemMethod = null;
      for ( Method method : classGen.getMethods() )
      {
         if ( method.getName().equals( "getFirstItem" ) )
         {
            getFirstItemMethod = method;
            break;
         }
      }

      // dump the LocalVariableTable attribute
      System.out.println( "LocalVariableTable of original" );
      System.out.println( "------------------------------" );
      for ( LocalVariable localVariable :
getFirstItemMethod.getLocalVariableTable().getLocalVariableTable() )
      {
         System.out.println( localVariable.getName() + "\t" +
localVariable.getIndex() + "\t" + localVariable.getSignature() );
      }
      System.out.println();

      // dump the LocalVariableTypeTable attribute
      for ( Attribute attribute : getFirstItemMethod.getCode().getAttributes()
)
      {
         if ( attribute instanceof LocalVariableTypeTable )
         {
            System.out.println( "LocalVariableTypeTable of original" );
            System.out.println( "----------------------------------" );
            for ( LocalVariable localVariable : ( (LocalVariableTypeTable)
attribute ).getLocalVariableTypeTable() )
            {
               System.out.println( localVariable.getName() + "\t" +
localVariable.getIndex() + "\t" + localVariable.getSignature() );
            }
         }
      }
      System.out.println();

      // now convert to a MethodGen
      MethodGen methodGen = new MethodGen( getFirstItemMethod,
                                           classGen.getClassName(),
                                           classGen.getConstantPool() );

      // dump the LocalVariableTable
      System.out.println( "LocalVariableTable of MethodGen" );
      System.out.println( "-------------------------------" );
      for ( LocalVariableGen localVariableGen : methodGen.getLocalVariables() )
      {
         System.out.println( localVariableGen.getName() + "\t" +
localVariableGen.getIndex() + "\t" + localVariableGen.getType() );
      }
   }

}


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 45217] MethodGen: LocalVariableTableGen issues

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45217





--- Comment #2 from Matthew Wilson <mj...@googlemail.com>  2008-06-16 13:22:09 PST ---
The issue is here, AFAICT, in the constructor of MethodGen:


...
                    } else if (a instanceof LocalVariableTable) {
                        LocalVariable[] lv = ((LocalVariableTable)
a).getLocalVariableTable();
                        removeLocalVariables();
                        // [snip]
                    } else if (a instanceof LocalVariableTypeTable) {
                        LocalVariable[] lv = ((LocalVariableTypeTable)
a).getLocalVariableTypeTable();
                        removeLocalVariables();
...

It fills in the local variables from the LocalVariableTypeTable as well, but
removes the variables declared in LocalVariableTable.  Since the
LocalVariableTypeTable only includes variables with generics (or so it seems
that Eclipse's compiler does that), the other variables are removed.  It should
be fairly safe to remove that 'removeLocalVariables()' call.

The other part of the issue is Type.getType(String) not parsing the generic
types correctly.  I'm not sure what the best thing to do is there, though.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org