4 Replies Latest reply on Jul 17, 2007 11:07 AM by florian Nouviale

    ldc operand is null

    Ben Klages Newbie

      Hi all,

      I am having a problem preverifying a class I have modified using javassist. A method that I have in my class has changed from

      3: dup
      4: invokespecial #53; //Method java/lang/StringBuffer."":()V
      7: ldc #54; //String /
      9: invokevirtual #55; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
      12: iload_1

      to now include a nop and an ldc #0

      3: dup
      4: invokespecial #254; //Method java/lang/StringBuffer."":()V
      7: ldc_w #256; //String /
      10: nop
      11: ldc #0; //#0
      13: invokevirtual #260; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
      16: iload_1

      This is causing the preverifier to complain. The constant pool entry for '/' has changed and caused it to use ldc_w but why would it then put the ldc #0 in? Anyone got any ideas?

      Cheers

      Ben

        • 1. Re: ldc operand is null
          Shigeru Chiba Expert

          How did you modify your method with Javassist?
          It might be a bug.

          Chiba

          • 2. Re: ldc operand is null
            Ben Klages Newbie

            Well strangely I didn't actually modify this method, but I have added methods to the class and increased the size of the constant pool enough to make the ldc change to an ldc_w.

            Having taken a look at the code and debuged my classes I can see it finding the ldc and creating linked list of the final class LdcEntry. It then iterates through each of these (only two in my case), inserts a gap, and then places the ldc_w opcode plus the 16 bit index. It looks like the insertGap2 method in codeIterator is inserting one NOP opcode but then copying the old ldc opcode into the new code before carrying on with the invokevirtual - if you see what I mean. I don't know if this is right? It seems to produce the byte codes that I have shown, which the preverifier is complaining about. Should it not place enough NOP opcodes and then carry on copying the code from the invoke virtual?

            Cheers for the help.

            • 3. Re: ldc operand is null
              Ben Klages Newbie

              I have found even more. The problem seems to stem from the fact that insertGap in codeIterator doesn't nescessarily insert a gap of the gapLength but will insert a gap of gapLength + 3 if an alignment expcetion is thrown. An alignment exception is thrown because my code has a switch statement in it. Thus when the original code would have been overwritten it is not because there is a gap of 4 rather than 1.

              Hope this helps.

              Ben

              • 4. Re: ldc operand is null
                florian Nouviale Newbie

                Hello,

                I'm having a similar problem. Has this issue been solved??

                Thanks