File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect
spotbugsTestCases/src/java/multithreaded/sharedPrimitiveVariables Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,14 @@ void noBugSynchronizedBlockSeparateMethod() {
129
129
assertBugTypeCount (OPS_BUG , 0 );
130
130
}
131
131
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
+
132
140
@ Test
133
141
void noBugCompoundOpOnAtomicVariable () {
134
142
performAnalysis ("multithreaded/compoundOperationOnSharedVariables/CompoundOperationOnSharedAtomicVariable.class" );
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments