History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-24277
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Maxim Shafirov
Reporter: Jonas Kvarnstrom
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

Quickfix for "condition is always true" mangles code, changes semantics

Created: 21 Aug 07 12:00   Updated: 15 Jan 08 18:38
Component/s: Code Analysis. Inspection
Fix Version/s: Diana Final, Selena 7.0.3

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 7,123
Fixed in build: 8,099
Severity: Extreme


 Description  « Hide
In the following class, "args != null" is always true:

{{code}package test;

// 7.0M2
public class TestIfElseFix
{
public static void main(String[] args) {
if (args.length == 0) { System.out.println("No args"); } else if (args != null) { System.out.println("Args"); System.out.println("Args again"); }
}
}{{code}

Accepting the quickfix at "args != null" leads to the following:

{{code}}package test;

// 7.0M2
public class TestIfElseFix
{
public static void main(String[] args) {
if (args.length == 0) { System.out.println("No args"); } } else System.out.println("Args");
System.out.println("Args again");
}
}code

Notice that the braces are gone and "Args again" will always be printed. Depending on the original layout of the code it can be easy for this to slip by, introducing subtle bugs.



 All   Comments   Work Log   Change History      Sort Order:
Jonas Kvarnstrom - 11 Jan 08 15:44
Still present; I hope it will be fixed in 7.0.x since it changes the semantics of the code in a way you could easily miss.