Menu

#13 Return statements in loop bodies cause problems

open
None
5
2007-04-18
2007-04-18
No

When a return statement is inside a loop, Clepsydra (and probably Cascade, too) produce invalid results.

For example, this code causes problems because it has two ReturnStatement nodes:

while (val > 3)
if (b) return;

Here's another example; this one causes an ArrayIndexOutOfBoundsException:

while (val > 3)
if (b) return;
b = true;

Return statements inside other types of loops should also be checked.

Discussion

  • Trevor Harmon

    Trevor Harmon - 2007-04-18

    Logged In: YES
    user_id=720008
    Originator: YES

    Beware of potential problems, such as the strange bytecode produced by this example:

    while (val > 3)
    if (b)
    {
    b = true;
    return;
    }

     
  • Trevor Harmon

    Trevor Harmon - 2007-04-18
    • assigned_to: nobody --> vocaro
     

Log in to post a comment.