Skip to content

Commit

Permalink
Fixes issue spotbugs#1313
Browse files Browse the repository at this point in the history
fix for issue 1313, do not report volatile problems in synthetic code

With the fix for Eclipse bug 544521,
https://bugs.eclipse.org/bugs/show_bug.cgi?id=544521, the Eclipse 4.17+
Java compiler will generate synthetic code for switch expressions.
spotbugs reports VO_VOLATILE_REFERENCE_TO_ARRAY issues in this synthetic
code.

This changes makes spotbugs ignore synthetic fields during
VO_VOLATILE_REFERENCE_TO_ARRAY analysis.
  • Loading branch information
trancexpress committed Oct 16, 2020
1 parent 753ae58 commit 3d047b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This is the changelog for SpotBugs. This follows [Keep a Changelog v1.0.0](http:
Currently the versioning policy of this project follows [Semantic Versioning v2.0.0](http://semver.org/spec/v2.0.0.html).

## Unreleased - 2020-??-??
### Fixed
* spotbugs reports `VO_VOLATILE_REFERENCE_TO_ARRAY` in synthetic code generated by Eclipse 4.17+ Java compiler ([#1313](https://github.com/spotbugs/spotbugs/issues/1313))

## 4.1.4 - 2020-10-15
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void report() {
Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();

for (XField f : AnalysisContext.currentXFactory().allFields()) {
if (isVolatileArray(f) && subtypes2.isApplicationClass(f.getClassDescriptor())) {
if (!f.isSynthetic() && isVolatileArray(f) && subtypes2.isApplicationClass(f.getClassDescriptor())) {
int priority = LOW_PRIORITY;
if (initializationWrites.contains(f) && !otherWrites.contains(f)) {
priority = NORMAL_PRIORITY;
Expand Down
24 changes: 24 additions & 0 deletions spotbugsTestCases/src/java/ghIssues/issue1313/Issue1313.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ghIssues.issue1313;

/**
* Manual test snippet for issue 1313.
*/
public class Issue1313 {

enum TestEnum {
TEST_ENUM_VALUE1, TEST_ENUM_VALUE2,
}

static void println(TestEnum testEnum) {
switch (testEnum) {
case TEST_ENUM_VALUE1:
System.out.println("TEST_ENUM_VALUE1");
break;
case TEST_ENUM_VALUE2:
System.out.println("TEST_ENUM_VALUE2");
break;
default:
System.out.println("unknown enum value");
}
}
}

0 comments on commit 3d047b9

Please sign in to comment.