Janino

Code missed out after "if (true) return;"

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    6

Description

Hi all

Here is a test case for a bug in Janino 2.3.18.

public class Branch {
    public static void main(String[] args) {
        try {
            {
                System.out.println("set1");
            }
            {
                boolean tmp4 = false;
                if (tmp4) {
                    {
                        System.out.println("if true");
                        if (true) return;
                    }
                }
            }
            {
                System.out.println("return");
            }
        } catch (Exception e) {
            System.out.println("exception");
        } finally {
            System.out.println("finally");
        }
    }
}

$ javac Branch.java

$ java Branch
set1
return
finally

$ janinoc Branch.java

$ java Branch
set1
finally

The janino compiled code seems to jump from the if () statement
to the end of the method instead of to the start of the block
containing the return statement.

cheers
Mo DeJong

  1. Loop1.java
    09/May/06 3:51 PM
    0.3 kB
    Arno Unkrig
  2. Loop2.java
    09/May/06 3:51 PM
    0.2 kB
    Arno Unkrig
  3. Loop3.java
    09/May/06 3:51 PM
    0.2 kB
    Arno Unkrig
  4. Loop4.java
    09/May/06 3:52 PM
    0.1 kB
    Arno Unkrig
  5. Loop5.java
    09/May/06 3:52 PM
    0.2 kB
    Arno Unkrig
  6. Loop6.java
    09/May/06 3:52 PM
    0.5 kB
    Arno Unkrig

Activity

Hide
Arno Unkrig added a comment -

Hello Arno

I am running into a problem with Janino having to do with code that
is incorrectly flagged as unreachable. I am using Janino 2.3.18.
The problem is related to this earlier bug report:

http://jira.codehaus.org/browse/JANINO-41

The trouble I am having now is that a loop will not notice when
the "keepCompiling" flag for a block is set to false.

% cat loop/Loop1.java

public class Loop1 {
    void foo() {
        while (true) {
            if (true) {
                break;
            }
            return;
        }
    }
    void bar() {
        while (true) {
            {
                if (true) {
                    break;
                }
            }
            return;
        }
    }
}

When compiling this code, I would get an error saying that the
return statement was not reachable. I poked around in the
source code and found what I think is the right place to patch
the problem. Included in the loop.zip file is a patch file named
loop.patch that fixes the above test case for me. Trouble is,
it does not fix all the loop problems I have run into. So, I created
the following simple test cases related to loop conditions in
the hope that these tests would help to identify the problem areas.

Loop1.java
Loop2.java
Loop3.java
Loop4.java
Loop5.java
Loop6.java

Each one compiles just fine with Javac but they fail with Janino.

I hope this helps
Mo DeJong

Show
Arno Unkrig added a comment - Hello Arno I am running into a problem with Janino having to do with code that is incorrectly flagged as unreachable. I am using Janino 2.3.18. The problem is related to this earlier bug report: http://jira.codehaus.org/browse/JANINO-41 The trouble I am having now is that a loop will not notice when the "keepCompiling" flag for a block is set to false. % cat loop/Loop1.java
public class Loop1 {
    void foo() {
        while (true) {
            if (true) {
                break;
            }
            return;
        }
    }
    void bar() {
        while (true) {
            {
                if (true) {
                    break;
                }
            }
            return;
        }
    }
}
When compiling this code, I would get an error saying that the return statement was not reachable. I poked around in the source code and found what I think is the right place to patch the problem. Included in the loop.zip file is a patch file named loop.patch that fixes the above test case for me. Trouble is, it does not fix all the loop problems I have run into. So, I created the following simple test cases related to loop conditions in the hope that these tests would help to identify the problem areas. Loop1.java Loop2.java Loop3.java Loop4.java Loop5.java Loop6.java Each one compiles just fine with Javac but they fail with Janino. I hope this helps Mo DeJong
Hide
Arno Unkrig added a comment -

The bug described in the DESCRIPTION section ("class Branch") seems to be fixed with 2.4.2. Need to check out Loop1...6.java. Where did I put them? Dammit. That's what happens when you copy emails to JIRA!

Show
Arno Unkrig added a comment - The bug described in the DESCRIPTION section ("class Branch") seems to be fixed with 2.4.2. Need to check out Loop1...6.java. Where did I put them? Dammit. That's what happens when you copy emails to JIRA!
Hide
Arno Unkrig added a comment -

Got it! Fix will be released in version 2.4.3

Your Test "Loop4" is buggy – JANINO reports an error "Loop update is unreachable", which is correct. The others now compile without errors.

Show
Arno Unkrig added a comment - Got it! Fix will be released in version 2.4.3 Your Test "Loop4" is buggy – JANINO reports an error "Loop update is unreachable", which is correct. The others now compile without errors.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: