Skip to content

Commit 0e9a1a9

Browse files
committed
add test
1 parent 9f6103c commit 0e9a1a9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/SharedVariableAtomicityDetectorTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ void noBugSynchronizedBlockSeparateMethod() {
129129
assertBugTypeCount(OPS_BUG, 0);
130130
}
131131

132+
@Test
133+
void noBugSynchronizedBlockPrimitiveSeparateMethod() {
134+
performAnalysis("multithreaded/sharedPrimitiveVariables/SynchronizedBlockPrimitiveSeparateMethod.class");
135+
assertBugTypeCount(PRIMITIVE_BUG, 0);
136+
assertBugTypeCount(WRITE_64BIT_BUG, 0);
137+
assertBugTypeCount(OPS_BUG, 0);
138+
}
139+
132140
@Test
133141
void noBugCompoundOpOnAtomicVariable() {
134142
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundOperationOnSharedAtomicVariable.class");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package multithreaded.sharedPrimitiveVariables;
2+
3+
public class SynchronizedBlockPrimitiveSeparateMethod implements Runnable {
4+
private boolean done = false;
5+
6+
@Override
7+
public void run() {
8+
synchronized (SynchronizedBlockPrimitiveSeparateMethod.class) {
9+
while (!isDone()) {
10+
try {
11+
// ...
12+
Thread.sleep(1000); // Do something
13+
} catch(InterruptedException ie) {
14+
Thread.currentThread().interrupt(); // Reset interrupted status
15+
}
16+
}
17+
}
18+
}
19+
20+
private boolean isDone() {
21+
return done;
22+
}
23+
24+
public void shutdown() {
25+
synchronized (SynchronizedBlockPrimitiveSeparateMethod.class) {
26+
done = true;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)