forked from spotbugs/spotbugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: reproducer for issue spotbugs#3310
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue3310Test.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,15 @@ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class Issue3310Test extends AbstractIntegrationTest { | ||
|
||
@Test | ||
void testIssue() { | ||
performAnalysis("ghIssues/Issue3310.class", | ||
"ghIssues/Issue3310$Result.class"); | ||
|
||
assertNoBugInClass("AT_STALE_THREAD_WRITE_OF_PRIMITIVE", "Issue3310"); | ||
} | ||
} |
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,31 @@ | ||
package ghIssues; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.util.Map; | ||
|
||
public class Issue3310 { | ||
private volatile int x; | ||
|
||
public <K, V> Object test(Map<K, V> map, K key) { | ||
Result result = new Result(); | ||
map.compute(key, (k, oldValue) -> { | ||
V newValue = oldValue; | ||
result.written = true; | ||
return newValue; | ||
}); | ||
|
||
if (result.written) { | ||
return result; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public void setX(int x) { | ||
this.x = x; | ||
} | ||
|
||
public static class Result { | ||
boolean written; | ||
} | ||
} |