Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,25 @@ void method() {
value++; // Noncompliant
}
}

record Vinyl(String singer, String title, int year) {
static volatile int counter = 0;
static int nonVolatile = 0;

void method() {
counter++; // Noncompliant
nonVolatile++;
}
}

class Container {
static volatile int counter = 0;
static int nonVolatile = 0;
}

interface MyInterface {
default void method() {
Container.counter++; // Noncompliant
Container.nonVolatile++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
volatile int count1 = 0;
int nonVolatileCount1 = 0;
volatile boolean boo1 = false;

void main() {
count1++; // Noncompliant {{Use an "AtomicInteger" for this field; its operations are atomic.}}
nonVolatileCount1++;
boo1 = !boo1; // Noncompliant {{Use an "AtomicBoolean" for this field; its operations are atomic.}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,17 @@ private void reportIssueIfNotInExcludedContext(Tree tree, String recommendedType
}
break;
case ENUM,
CLASS:
if (((ClassTree) current).simpleName() == null) {
CLASS,
INTERFACE,
RECORD,
IMPLICIT_CLASS:
Comment on lines +128 to +131
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that interfaces (with default implementation) and records should also be checked here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (!current.is(Tree.Kind.IMPLICIT_CLASS) && ((ClassTree) current).simpleName() == null) {
return;
}
// we got to a non anonymous class, we can safely raise an issue
// we got to a non-anonymous class or implicit class in compact source file, we can safely raise an issue
foundClass = true;
break;

}
current = current.parent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ void test() {
.withCheck(new VolatileVariablesOperationsCheck())
.verifyIssues();
}

@Test
void test_compact_source() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/VolatileVariablesOperationsCheckCompactSource.java"))
.withCheck(new VolatileVariablesOperationsCheck())
.verifyIssues();
}
}