New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduced detector for rule VNA-00 and VNA-02 with test cases #2077
Open
gonczmisi
wants to merge
15
commits into
spotbugs:master
Choose a base branch
from
gonczmisi:vna-00
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,751
−0
Open
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3722f90
Introduced detector for rule VNA-00 and VNA-02 with test cases
gonczmisi 18c633d
Merge branch 'master' into vna-00
gonczmisi 58743f9
Description for COSV bug and cleanup
gonczmisi 7be029f
Fixed packaging error
gonczmisi 1745125
Merge branch 'spotbugs:master' into vna-00
gonczmisi c6900e1
PR review fixes: pre-test ful debug logging command, fixed typos, add…
gonczmisi eea20b0
Aligned line numbers for tests with linceses
gonczmisi 5c9ce1b
PR review fixes v2
gonczmisi 866ba78
Merge branch 'spotbugs:master' into vna-00
gonczmisi 095e22e
Merge branch 'master' into vna-00
KengoTODA a7efab4
Missing diamond operators, fixed misuse of Optional type
gonczmisi 48b79a5
Merge branch 'master' into vna-00
gonczmisi 3a60795
Rephrased bugpattern details
gonczmisi 13674fc
Merge branch 'master' into vna-00
gonczmisi 11bf124
Merge branch 'spotbugs:master' into vna-00
gonczmisi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...src/test/java/edu/umd/cs/findbugs/detect/BadVisibilityOnSharedPrimitiveVariablesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.SystemProperties; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
import org.junit.Test; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasItem; | ||
|
||
public class BadVisibilityOnSharedPrimitiveVariablesTest extends AbstractIntegrationTest { | ||
|
||
@Test | ||
public void failurePath_fieldWithBadVisibility_whenOtherMethodHasSynchronizedBlock() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
gonczmisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
performAnalysis("multithreaded/sharedPrimitiveVariables/SynchronizedBlockAndBadVisibilityOnField.class"); | ||
|
||
assertSPVNumOfBugs(1); | ||
assertSPVBug("SynchronizedBlockAndBadVisibilityOnField", "shutdown", 17); | ||
} | ||
|
||
@Test | ||
public void failurePath_fieldWithBadVisibility_whenOtherMethodIsSynchronized() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/sharedPrimitiveVariables/SynchronizedMethodAndBadVisibilityOnField.class"); | ||
|
||
assertSPVNumOfBugs(1); | ||
assertSPVBug("SynchronizedMethodAndBadVisibilityOnField", "shutdown", 17); | ||
} | ||
|
||
@Test | ||
public void failurePath_fieldWithBadVisibility_whenClassExtendsThread() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/sharedPrimitiveVariables/FieldWithBadVisibilityThread.class"); | ||
|
||
assertSPVNumOfBugs(1); | ||
assertSPVBug("FieldWithBadVisibilityThread", "shutdown", 18); | ||
} | ||
|
||
@Test | ||
public void failurePath_fieldWithBadVisibility_whenClassImplementsRunnable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/sharedPrimitiveVariables/FieldWithBadVisibilityRunnable.class"); | ||
|
||
assertSPVNumOfBugs(1); | ||
assertSPVBug("FieldWithBadVisibilityRunnable", "shutdown", 18); | ||
} | ||
|
||
@Test | ||
public void happyPath_atomicField() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/sharedPrimitiveVariables/AtomicField.class"); | ||
|
||
assertSPVNumOfBugs(0); | ||
} | ||
|
||
@Test | ||
public void happyPath_volatileField() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/sharedPrimitiveVariables/VolatileField.class"); | ||
|
||
assertSPVNumOfBugs(0); | ||
} | ||
|
||
@Test | ||
public void happyPath_synchronizedBlock() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/sharedPrimitiveVariables/SynchronizedBlock.class"); | ||
|
||
assertSPVNumOfBugs(0); | ||
} | ||
|
||
@Test | ||
public void happyPath_synchronizedMethod() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/sharedPrimitiveVariables/SynchronizedMethod.class"); | ||
|
||
assertSPVNumOfBugs(0); | ||
} | ||
|
||
private void assertSPVNumOfBugs(int num) { | ||
final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() | ||
.bugType("SPV_BAD_VISIBILITY_ON_SHARED_PRIMITIVE_VARIABLES") | ||
.build(); | ||
assertThat(getBugCollection(), containsExactly(num, bugTypeMatcher)); | ||
} | ||
|
||
private void assertSPVBug(String className, String methodName, int line) { | ||
final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder() | ||
.bugType("SPV_BAD_VISIBILITY_ON_SHARED_PRIMITIVE_VARIABLES") | ||
.inClass(className) | ||
.inMethod(methodName) | ||
.atLine(line) | ||
.build(); | ||
assertThat(getBugCollection(), hasItem(bugInstanceMatcher)); | ||
} | ||
|
||
} |
207 changes: 207 additions & 0 deletions
207
...src/test/java/edu/umd/cs/findbugs/detect/FindCompoundOperationsOnSharedVariablesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.SystemProperties; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
import org.junit.Test; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.hamcrest.Matchers.hasItem; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class FindCompoundOperationsOnSharedVariablesTest extends AbstractIntegrationTest { | ||
|
||
@Test | ||
public void happyPath_compoundOperation_onSharedAtomicVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundOperationOnSharedAtomicVariable.class"); | ||
|
||
assertCOSVNumOfBugs(0); | ||
} | ||
|
||
@Test | ||
public void happyPath_compoundOperationInsideSynchronizedBlock_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/SynchronizedBlockCompoundOperationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(0); | ||
} | ||
|
||
@Test | ||
public void happyPath_compoundOperationInsideSynchronizedMethod_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/SynchronizedMethodCompoundOperationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(0); | ||
} | ||
|
||
// --num | ||
@Test | ||
public void reportsBugFor_compoundPreDecrementation_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundPreDecrementationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundPreDecrementationOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// num-- | ||
@Test | ||
public void reportsBugFor_compoundPostDecrementation_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundPostDecrementationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundPostDecrementationOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// ++num | ||
@Test | ||
public void reportsBugFor_compoundPreIncrementation_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundPreIncrementationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundPreIncrementationOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// num++ | ||
@Test | ||
public void reportsBugFor_compoundPostIncrementation_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundPostIncrementationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundPostIncrementationOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// &= | ||
@Test | ||
public void reportsBugFor_compoundIAND_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundIANDOperationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundIANDOperationOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// |= | ||
@Test | ||
public void reportsBugFor_compoundIOR_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundIOROperationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundIOROperationOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// >>>= | ||
@Test | ||
public void reportsBugFor_compoundLogicalRightShifting_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundLogicalRightShiftingOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundLogicalRightShiftingOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// >>= | ||
@Test | ||
public void reportsBugFor_compoundRightShifting_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundRightShiftingOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundRightShiftingOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// <<= | ||
@Test | ||
public void reportsBugFor_compoundLeftShifting_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundLeftShiftingOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundLeftShiftingOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// %= | ||
@Test | ||
public void reportsBugFor_compoundModulo_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundModuloOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundModuloOnSharedVariable", "getNum", 12); | ||
} | ||
|
||
// *= | ||
@Test | ||
public void reportsBugFor_compoundMultiplication_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundMultiplicationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundMultiplicationOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// /= | ||
@Test | ||
public void reportsBugFor_compoundDivision_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundDivisionOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundDivisionOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
// -= | ||
@Test | ||
public void reportsBugFor_compoundSubtraction_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundSubtractionOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundSubtractionOnSharedVariable", "getNum", 11); | ||
} | ||
|
||
|
||
// += | ||
@Test | ||
public void reportsBugFor_compoundAddition_onSharedVolatileVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundAdditionOnSharedVolatileVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundAdditionOnSharedVolatileVariable", "getNum", 11); | ||
} | ||
|
||
// ^= | ||
@Test | ||
public void reportsBugFor_compoundXOROperation_onSharedVariable() { | ||
SystemProperties.setProperty("ful.debug", "true"); | ||
performAnalysis("multithreaded/compoundOperationOnSharedVariables/CompoundXOROperationOnSharedVariable.class"); | ||
|
||
assertCOSVNumOfBugs(1); | ||
assertCOSVBug("CompoundXOROperationOnSharedVariable", "getFlag", 11); | ||
} | ||
|
||
private void assertCOSVNumOfBugs(int num) { | ||
final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() | ||
.bugType("COSV_COMPOUND_OPERATIONS_ON_SHARED_VARIABLES") | ||
.build(); | ||
assertThat(getBugCollection(), containsExactly(num, bugTypeMatcher)); | ||
} | ||
|
||
private void assertCOSVBug(String className, String methodName, int line) { | ||
final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder() | ||
.bugType("COSV_COMPOUND_OPERATIONS_ON_SHARED_VARIABLES") | ||
.inClass(className) | ||
.inMethod(methodName) | ||
.atLine(line) | ||
.build(); | ||
assertThat(getBugCollection(), hasItem(bugInstanceMatcher)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already an
Added
section in Unreleased. Can you please merge the two?