Skip to content

Commit

Permalink
add more test for BadVisibilityOnSharedPrimitiveVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
JuditKnoll committed Nov 22, 2024
1 parent 60c84b5 commit 0ecb1d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ void failurePath_fieldWithBadVisibility_whenOtherMethodHasSynchronizedBlock() {
assertBugInMethodAtLine(BUG_TYPE, "SynchronizedBlockAndBadVisibilityOnField", "shutdown", 17);
}

@Test
void failurePath_fieldWithBadVisibility_whenMethodHasIrrelevantSynchronizedBlock() {
performAnalysis("multithreaded/sharedPrimitiveVariables/SynchronizedBlockWithBadVisibilityOnField.class");
assertBugTypeCount(BUG_TYPE, 1);
assertBugInMethodAtLine(BUG_TYPE, "SynchronizedBlockWithBadVisibilityOnField", "shutdown", 20);
}

@Test
void failurePath_fieldWithBadVisibility_whenOtherMethodIsSynchronized() {
performAnalysis("multithreaded/sharedPrimitiveVariables/SynchronizedMethodAndBadVisibilityOnField.class");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package multithreaded.sharedPrimitiveVariables;

public class SynchronizedBlockWithBadVisibilityOnField {
private boolean done = false;

public void run() {
synchronized (SynchronizedBlockWithBadVisibilityOnField.class) {
System.out.println("this is synchronized, but not the whole method");
}
while (!done) {
try {
Thread.currentThread().sleep(1000);
} catch(InterruptedException ie) {
Thread.currentThread().interrupt();
}
}
}

public void shutdown() {
done = true;
}
}

0 comments on commit 0ecb1d0

Please sign in to comment.