[
https://issues.apache.org/jira/browse/BCEL-369?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17733778#comment-17733778
]
Katherine Hough commented on BCEL-369:
--------------------------------------
A check to line 271 of Pass3bVerifier#circulationPump that the
InstructionHandle ih is a top-level instruction.
I assume the best way to check this would be to add a method to
ControlFlowGraph like:
{code:java}
public boolean isTopLevel(final InstructionHandle i) {
return subroutines.subroutineOf(i) == subroutines.getTopLevel();
}{code}
Then, line 271 of Pass3bVerifier#circulationPump would be:
{code:java}
if (ih.getInstruction() instanceof ReturnInstruction && !cfg.isDead(ih) &&
cfg.isTopLevel(ih)) {{code}
This should fix this specific crash and it would mean the code matches the
comment on line 273 of Pass3bVerifier which says, "TODO: This is buggy, we
check only the top-level return instructions this way." However this change
would not resolve that TODO. Return instructions in subroutines would still not
be properly checked, but they would no longer produce an
org.apache.bcel.verifier.exc.AssertionViolatedException. I am not sure what
change would need to be made to properly check RETURN instructions in
subroutines.
> org.apache.bcel.verifier.exc.AssertionViolatedException from method return in
> subroutine
> ----------------------------------------------------------------------------------------
>
> Key: BCEL-369
> URL: https://issues.apache.org/jira/browse/BCEL-369
> Project: Commons BCEL
> Issue Type: Bug
> Components: Verifier
> Affects Versions: 6.7.0, 6.8.0
> Reporter: Katherine Hough
> Priority: Minor
> Attachments: Test-1.class
>
>
> Verifier pass 3B fails due to a method return in a subroutine.
> There is a comment in the associated code indicating that you are likely
> already aware of this issue:
> "// TODO: This is buggy, we check only the top-level return instructions this
> way.
> // Maybe some maniac returns from a method when in a subroutine?"
>
> The attached class file is what javac for the Java HotSpot SE Development Kit
> build 1.4.2_19-b04 produced for the program:
> {code:java}
> class Test {
> public Test(int i) {
> try {
> i++;
> } finally {
> if(i == 0) {
> return;
> }
> int u = 7;
> u += 9;
> }
> i++;
> }
> }{code}
> Input: See attached file.
> Output:
> {code:java}
> Apache Commons BCEL
> https://commons.apache.org/bcel
> Now verifying: Test
> Pass 1:
> VERIFIED_OK
> Passed verification.
> Pass 2:
> VERIFIED_OK
> Passed verification.
> Pass 3a, method number 0 ['public void <init>(int arg1)']:
> VERIFIED_OK
> Passed verification.
> Exception in thread "main"
> org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL ERROR: Some
> RuntimeException occurred while verify()ing class 'Test', method 'public void
> <init>(int arg1)'. Original RuntimeException's stack trace:
> ---
> org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL ERROR:
> outFrame not set! This:
> 24: return [InstructionContext]
> ExecutionChain: 24: return [InstructionContext]
> OutFrames: '{ 7: jsr -> 19 [InstructionContext]=Local Variables:
> 0: Test
> 1: int
> 2: <unknown object>
> 3: <return address targeting 10: goto[167](3) -> 34>
> 4: <unknown object>
> OperandStack:
> Slots used: 0 MaxStack: 1.
> , 14: jsr -> 19 [InstructionContext]=Local Variables:
> 0: Test
> 1: int
> 2: java.lang.Throwable
> 3: <return address targeting 17: aload_2[44](1)>
> 4: <unknown object>
> OperandStack:
> Slots used: 0 MaxStack: 1.
> }'.
> at
> org.apache.bcel.verifier.structurals.ControlFlowGraph$InstructionContextImpl.getOutFrame(ControlFlowGraph.java:285)
> at
> org.apache.bcel.verifier.structurals.Pass3bVerifier.circulationPump(Pass3bVerifier.java:275)
> at
> org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386)
> at org.apache.bcel.verifier.PassVerifier.verify(PassVerifier.java:98)
> at org.apache.bcel.verifier.Verifier.doPass3b(Verifier.java:166)
> at org.apache.bcel.verifier.Verifier.verifyType(Verifier.java:90)
> at org.apache.bcel.verifier.Verifier.main(Verifier.java:69)
> ---
> at
> org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:398)
> at org.apache.bcel.verifier.PassVerifier.verify(PassVerifier.java:98)
> at org.apache.bcel.verifier.Verifier.doPass3b(Verifier.java:166)
> at org.apache.bcel.verifier.Verifier.verifyType(Verifier.java:90)
> at org.apache.bcel.verifier.Verifier.main(Verifier.java:69)
> Caused by: org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL
> ERROR: outFrame not set! This:
> 24: return [InstructionContext]
> ExecutionChain: 24: return [InstructionContext]
> OutFrames: '{ 7: jsr -> 19 [InstructionContext]=Local Variables:
> 0: Test
> 1: int
> 2: <unknown object>
> 3: <return address targeting 10: goto[167](3) -> 34>
> 4: <unknown object>
> OperandStack:
> Slots used: 0 MaxStack: 1.
> , 14: jsr -> 19 [InstructionContext]=Local Variables:
> 0: Test
> 1: int
> 2: java.lang.Throwable
> 3: <return address targeting 17: aload_2[44](1)>
> 4: <unknown object>
> OperandStack:
> Slots used: 0 MaxStack: 1.
> }'.
> at
> org.apache.bcel.verifier.structurals.ControlFlowGraph$InstructionContextImpl.getOutFrame(ControlFlowGraph.java:285)
> at
> org.apache.bcel.verifier.structurals.Pass3bVerifier.circulationPump(Pass3bVerifier.java:275)
> at
> org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386)
> ... 4 more
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)