XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 5.2
    • 6.0
    • Main
    • None

    Description

      It turned out that finder.search methods generates incorrect output.
      For example:

      finder.search("invokespecial")
      

      Will find not only some INVOKESPECIAL opcodes but will return InstructionHandle arrays in form:

      [   invokespecial,    nextOpCode]
      

      So instead of returning x matching opcode(s) it returns x+1 matching opcodes in one IntructionHandle array. This generates problem when invoking finder.search("invokespecial return") which will throw

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
      	at java.lang.System.arraycopy(Native Method)
      	at org.apache.bcel.util.InstructionFinder.getMatch(InstructionFinder.java:171)
      	at org.apache.bcel.util.InstructionFinder.search(InstructionFinder.java:231)
      	at org.apache.bcel.util.InstructionFinder.search(InstructionFinder.java:250)
      	at Transform.transformMethod(Transform.java:66)
      	at Transform.main(Transform.java:25)
      

      because of situation, that after return there is no more instruction (so InstructionHandler too) to get. It occurs especially for default constructors as they bytecode is like:

      invokespecial
      return.
      

      Error exists because of erroneous instruction(line 230 in InstructionFinder.java, method search()):

      int lenExpr = (endExpr - startExpr) + 1;
      

      There should be no "+1" part because:

      int endExpr = matcher.end();
      

      (which is one line above)
      returns index AFTER match.
      So bug generally (I didn't tested properly) could be repaired with replacing erroneous line with:

      int lenExpr = (endExpr - startExpr);
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              drew Drew Farris
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: