Uploaded image for project: 'Commons BCEL'
  1. Commons BCEL
  2. BCEL-137

"Invalid method signature: TT;" when using MethodGen for a method having a generic parameter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: unspecified
    • Fix Version/s: 6.0
    • Component/s: Main
    • Labels:
      None

      Description

      The following code throws a "ClassFormatException: Invalid method signature: TT;" when executed:
      ===========================================================

      import org.apache.bcel.Repository;
      import org.apache.bcel.classfile.JavaClass;
      import org.apache.bcel.classfile.Method;
      import org.apache.bcel.generic.ConstantPoolGen;
      import org.apache.bcel.generic.MethodGen;

      class MyClassLoader extends ClassLoader {
      @Override
      public Class<?> loadClass(String name) throws ClassNotFoundException

      { if (name.startsWith("java.lang")) return super.loadClass(name); JavaClass jcl; jcl = Repository.lookupClass(name); scanMethods(jcl); byte[] data = jcl.getBytes(); return defineClass(name, data, 0, data.length); }

      private void scanMethods(JavaClass jcl) {
      ConstantPoolGen cpg = new ConstantPoolGen(jcl.getConstantPool());
      Method[] methods = jcl.getMethods();
      for (int i = 0; i < methods.length; i++)

      { MethodGen mg = new MethodGen(methods[i], jcl.getClassName(), cpg); }

      }
      }

      class Foo<T> {
      public void bar(T x) {
      }
      }

      public class MethSignTest {
      public MethSignTest()

      { Foo<Integer> foo = new Foo<Integer>(); }

      @SuppressWarnings("unchecked")
      public static void main(String[] args) {
      try

      { MyClassLoader mcl = new MyClassLoader(); Class<MethSignTest> c = (Class<MethSignTest>) mcl .loadClass(MethSignTest.class.getName()); c.newInstance(); }

      catch (Exception e)

      { e.printStackTrace(); }

      }
      }
      ===========================================================

      Here's the full stack trace:

      org.apache.bcel.classfile.ClassFormatException: Invalid method signature: TT;
      at org.apache.bcel.classfile.Utility.typeOfSignature(Utility.java:986)
      at org.apache.bcel.generic.Type.getType(Type.java:169)
      at org.apache.bcel.generic.MethodGen.<init>(MethodGen.java:255)
      at methodsignature.MyClassLoader.scanMethods(MethSignTest.java:26)
      at methodsignature.MyClassLoader.loadClass(MethSignTest.java:17)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
      at methodsignature.MethSignTest.<init>(MethSignTest.java:38)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:501)
      at java.lang.Class.newInstance0(Class.java:350)
      at java.lang.Class.newInstance(Class.java:303)
      at methodsignature.MethSignTest.main(MethSignTest.java:47)

      This misbehaviour occurs at least since revision 617860.

        Attachments

        1. patch.txt
          0.5 kB
          Enrico Gueli

          Activity

            People

            • Assignee:
              issues@commons.apache.org Apache Commons Developers
              Reporter:
              enrico.gueli@polito.it Enrico Gueli
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: