-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-1988 Handle properly unset constraint on wrapped sv
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
java-frontend/src/test/files/se/ConditionAlwaysTrueWithOptional.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.util.Optional; | ||
|
||
public class Squid2583 { | ||
|
||
private boolean isSpecial(MyObject obj) { | ||
return obj.getMyString().contains("B") && noEmptyNodeNames(obj) && foo(); // FP might be raised here because of optional in noEmptyNodeName method | ||
} | ||
|
||
private boolean noEmptyNodeNames(MyObject obj) { | ||
return obj.getValueOne().isPresent() && obj.getValueTwo().isPresent(); // constraint cleanup can cause absence of yields which can lead to FP. | ||
} | ||
|
||
public static final class MyObject { | ||
private String myString; | ||
private final Optional<String> valueOne; | ||
private final Optional<String> valueTwo; | ||
|
||
public MyObject() { | ||
} | ||
|
||
public String getMyString() { | ||
return myString; | ||
} | ||
|
||
public Optional<String> getValueOne() { | ||
return valueOne; | ||
} | ||
|
||
public Optional<String> getValueTwo() { | ||
return valueTwo; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters