-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-4233 Constants accessed with member-select create different…
… SV every time when placed in loops
- Loading branch information
1 parent
c071a14
commit a630731
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...ources/src/main/java/symbolicexecution/checks/NullDereferenceCheck_constants_in_loop.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,30 @@ | ||
package symbolicexecution.checks; | ||
|
||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
|
||
public abstract class NullDereferenceCheck_constants_in_loop { | ||
|
||
void foo(List<Object> items) { | ||
Integer max = null; | ||
for (Object item : items) { | ||
Integer value = getValue(item); | ||
if (value == null) { | ||
value = Integer.MAX_VALUE; // Should be a symbolic value from ConstraintManager#constants | ||
} | ||
if (max == null) { | ||
max = value; | ||
} else if (value == max) { | ||
max = value; | ||
} else if (value.equals(max)) { // Noncompliant {{A "NullPointerException" could be thrown; "value" is nullable here.}} | ||
doSomething(); | ||
} | ||
} | ||
} | ||
|
||
void doSomething() { } | ||
|
||
@Nullable | ||
abstract Integer getValue(Object o); | ||
|
||
} |
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
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