AK created BCEL-172:
-----------------------

             Summary: Searching bug
                 Key: BCEL-172
                 URL: https://issues.apache.org/jira/browse/BCEL-172
             Project: Commons BCEL
          Issue Type: Bug
          Components: Main
    Affects Versions: 5.2
            Reporter: AK


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 deafult constructors 
as they bytecode is like:
invokespecial
return.

Error exists because of errorneus 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 
errorneus line with:
int lenExpr = (endExpr - startExpr);




--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to