diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/BadVisibilityOnSharedPrimitiveVariablesTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/BadVisibilityOnSharedPrimitiveVariablesTest.java index 542a80a3d62..e536056d13c 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/BadVisibilityOnSharedPrimitiveVariablesTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/BadVisibilityOnSharedPrimitiveVariablesTest.java @@ -27,6 +27,14 @@ void failurePath_fieldWithBadVisibility_whenOtherMethodIsSynchronized() { assertBugInMethodAtLine(BUG_TYPE, "SynchronizedMethodAndBadVisibilityOnField", "shutdown", 17); } + @Test + void failurePath_fieldWithBadVisibility_whenClassHasTwoSetters() { + performAnalysis("multithreaded/sharedPrimitiveVariables/FieldWithBadVisibilityTwoSetters.class"); + assertBugTypeCount(BUG_TYPE, 2); + assertBugInMethodAtLine(BUG_TYPE, "FieldWithBadVisibilityTwoSetters", "shutdown", 18); + assertBugInMethodAtLine(BUG_TYPE, "FieldWithBadVisibilityTwoSetters", "up", 22); + } + @Test void failurePath_fieldWithBadVisibility_whenClassExtendsThread() { performAnalysis("multithreaded/sharedPrimitiveVariables/FieldWithBadVisibilityThread.class"); diff --git a/spotbugsTestCases/src/java/multithreaded/sharedPrimitiveVariables/FieldWithBadVisibilityTwoSetters.java b/spotbugsTestCases/src/java/multithreaded/sharedPrimitiveVariables/FieldWithBadVisibilityTwoSetters.java new file mode 100644 index 00000000000..2287235f867 --- /dev/null +++ b/spotbugsTestCases/src/java/multithreaded/sharedPrimitiveVariables/FieldWithBadVisibilityTwoSetters.java @@ -0,0 +1,24 @@ +package multithreaded.sharedPrimitiveVariables; + +public class FieldWithBadVisibilityTwoSetters extends Thread { + private boolean done = false; + + @Override + public void run() { + while (!done) { + try { + Thread.currentThread().sleep(1000); + } catch(InterruptedException ie) { + Thread.currentThread().interrupt(); + } + } + } + + public void shutdown() { + done = true; + } + + public void up() { + done = false; + } +}