0 Replies Latest reply on Oct 31, 2008 5:51 AM by kobevaliant

    Strange Exception: Register x contains wrong type

    kobevaliant

      Hi
      I think this is a bug of javassist.

       ClassPool pool = new ClassPool(true);
       CtClass ctc = pool.makeClass("my.Clazz");
       StringBuilder sb = new StringBuilder("public void test() {");
       for (int i = 0; i < 1000; i++) {
      
       sb.append("for(int i=0; i<10; i++) {}"); // line 1
      // sb.append("for(int i=0; i<10; i++) {int j=i;}"); // line 2
      
       }
      
       sb.append("}");
       ctc.addMethod(CtNewMethod.make(sb.toString(), ctc));
       ctc.toClass().newInstance();
      

      the code above will throw an exception:
      Exception in thread "main" java.lang.VerifyError: (class: my/Clazz, method: test signature: ()V) Register 0 contains wrong type

      But if you comment the line 1 and uncomment the line 2, there will no exception at all.

      It realy confuses me. Anyone who know the reason or workaround please tell me, this problem block the project I'm working on。

      Thanks