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
Issue #12099: Add ArchUnit test to ensure fields in modules and utils are immutable, and modules are correctly annotated #12135
Issue #12099: Add ArchUnit test to ensure fields in modules and utils are immutable, and modules are correctly annotated #12135
Conversation
513d326
to
e7f4583
Compare
src/test/java/com/puppycrawl/tools/checkstyle/internal/UtilClassesImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/UtilClassesImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/UtilClassesImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/UtilClassesImmutabilityTest.java
Outdated
Show resolved
Hide resolved
e7f4583
to
11a9806
Compare
"com.puppycrawl.tools.checkstyle.utils.CommonUtil.EMPTY_OBJECT_ARRAY", | ||
"com.puppycrawl.tools.checkstyle.utils.CommonUtil.EMPTY_STRING_ARRAY", | ||
"com.puppycrawl.tools.checkstyle.utils.TokenUtil.TOKEN_IDS", | ||
"com.puppycrawl.tools.checkstyle.utils.XpathUtil.TOKEN_TYPES_WITH_TEXT_ATTRIBUTE" |
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.
BitSet is mutable.
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.
Let's fix violations in a separate PR, for now this can stay in suppression list.
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.
Agreed, leaving for discussion.
2d7c1e4
to
66d782e
Compare
src/test/java/com/puppycrawl/tools/checkstyle/internal/UtilClassesImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/UtilClassesImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/UtilClassesImmutabilityTest.java
Outdated
Show resolved
Hide resolved
2a987b4
to
15451dd
Compare
15451dd
to
0881417
Compare
0881417
to
0a4c1e3
Compare
97405b9
to
f28ec2d
Compare
68545d1
to
82f682a
Compare
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.
Few more items, we are getting close now:
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
3de9398
to
ece76c4
Compare
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.
Immutability is still a somewhat nebulous definition to us, as we have no concrete way to say 100% that something is or isn't immutable. Let's make this method easy to understand and maintain as time goes on and we find more conditions to check.
Please also add some whitespace in here.
Items:
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
ece76c4
to
309ef76
Compare
@nrmancuso I enhanced the JavaDoc of the method to clarify further what are we trying to achieve. |
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.
a bit of minor changes please
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
309ef76
to
a1f9347
Compare
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.
@Vyom-Yadav please fix condition name/ logic
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
a1f9347
to
4fb26a6
Compare
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.
Did we discuss going over these suppressions, either in new issue or ... ?
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java
Outdated
Show resolved
Hide resolved
I recommend to apply all easy to fix items but all other, move to separate issue. |
dc72712
to
6bfd95d
Compare
0a69cd1
to
7bd92a7
Compare
"com.puppycrawl.tools.checkstyle.checks.naming.LambdaParameterNameCheck", | ||
"com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck", | ||
"com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck", | ||
"com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck", |
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.
Just a conversation while waiting for the last item to be done ( #12135 (comment) ),
MemberNameCheck
I took a look at this, and this class has no annotation on it. It extends AbstractAccessControlNameCheck
which also has no annotation on it. It also extends AbstractNameCheck
which has @StatelessCheck
on it.
Is this violation solely because the annotation is on parent class, which is 2 level deep?
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.
Violation is because the class itself has immutable fields (no fields in this case, not the inherited fields) and has no annotation.
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.
It has an annotation but not the main class itself. I assume that via reflection the annotation will show up, but I was curious if ArchUnit was not seeing the annotation?
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.
Yes, ArchUnit is not seeing it, it also has @Inherited
, I will report this to ArchUnit team.
… and utils are immutable, and modules are correctly annotated
7bd92a7
to
ec8c7a3
Compare
#12099
A brief about the changes in this PR:
ArchRules
, ArchUnit is just like English, so the rules are easy to understand.fieldsInUtilClassesShouldBeImmutable
fieldsInStatelessChecksShouldBeImmutable
classesWithImmutableFieldsShouldBeStateless
classesWithMutableFieldsShouldBeStateful