jakarta-bcel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 45217] MethodGen: LocalVariableTableGen issues
Date Mon, 16 Jun 2008 20:15:53 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=45217


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

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




--- Comment #1 from Matthew Wilson <mj.wilson.uk@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


Mime
View raw message