Skip to content

Commit

Permalink
add test to BadVisibilityOnSharedPrimitiveVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
JuditKnoll committed Nov 22, 2024
1 parent b820400 commit 5bd5168
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 5bd5168

Please sign in to comment.