-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Issue #16786: Ensure enum constants accessibility is properly evaluated #16787
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
Conversation
a312e2d
to
d962f2f
Compare
@JackPGreen , CI is very red, please address it. |
Thanks, fixed. |
@JackPGreen , please squash commits in one, CI does not like it, we need green CI |
9d985ee
to
7d6d054
Compare
Done :) |
@kkoutsilis , @mahfouz72 , please review update. Main point here is not Java spec, but more about javadoc tool behavior and user experience on documentations, no need to document what is not placed in html pages of javadoc. If user do care so much on doc on enum, he should put it at top level class. |
I think there are two separate issues here:
It's up to you whether (1) is worth addressing in isolation. |
I am ok with the update as it addresses the enum case. However, this issue is broader. We should verify whether a variable is truly accessible. So if we are going to fix this, we should handle all such cases, not just enums. Docs need to be updated also because right now it doesn't tell anything about true accesibility, it just talks about the direct access modifier of the variable I noticed that @kkoutsilis tried to handle such cases by using concepts like surroundingAccessModifier. But he got these reviews.
@kkoutsilis Will it be easy to bring back your work on trying to handle the surrounding/outer scope issue? |
I recommend to remove violation as hot fix, by merge of this PR, and in separate issue to do better support. |
I agree as well the changes in this PR looks good but I just wonder what about other tokens in the future ?
At least for the current issue of enums I see this PR is good to go but what about other tokens ? should they be handled separately in different PRs ? I think that this is not a big issue and user could just document the whole thing in an upper class for most of the tokens in the future but after taking a quick look on codebases that have inner types (classes, enums, etc..) they mostly document the inner class not just within the upper class e.g: Spring's codebase is full of this pattern
Since it is complicated on its own we might as well just handle enums for now and start discussing other tokens if needed to handle them at all |
Hey, to give my two cents here, this PR looks good for addressing the enums problem @JackPGreen faced, but this makes the check a bit confusing, as in all other cases it checks for direct access modifier, though for enums it checks the surrounding access modifier. The docs should be updated to clarify this behaviour before merging this PR. Overall, we probably need to decide if we keep the direct access modifier or refactor to use the surrounding access modifier for all cases. I don't have a strong opinion right now on one or the other, I just prefer consistency for all cases overall when possible. A good indication would be user feedback. If there are more confused or blocked users by this check's behaviour, then it's worth spending time on it. If there are no further complaints and users are happy, maybe it's not worth the discussion. Hope this makes sense.
@mahfouz72 If we decide to go with it, I can have a look. As you see from the previous PR I faced some issues with it 😅, but it should be possible. |
I'm here to say that this is stopping us upgrading to a more recent version of Checkstyle (without turning the (I found this PR while looking into the violations.) |
Thanks a lot for feedback. @james-baker-aera, can you check on your project that this fix is covering all your false positives? |
@JackPGreen , please update documentation to mention that we still consider interpretation of javadoc tool , when evaluating accessibility. |
I'm not sure that's sensible in it's current state - with this change, accessibility is only "properly" evaluated (i.e. considering parents) for I think improving the documentation would be better once ^ that ^ is properly addressed and it's simpler to explain. |
if we extend documentation to claim that we consider parents visiblity (no mentioning of javadoc tool), it will be enough. On future, there will be group of people who wants to not consider javadoc tool at all, as they use only IDE abilities to render javadoc during navigation over code. We will think in future on how to reconcile such use cases, lets proceed with focus on javadoc tool. |
Happy to add documentation, but struggling with the wording. I updating the docs, changing:
To:
Might help? Suggestions welcomed. |
Please add to all examples your junit test code.
|
7d6d054
to
5c5ce75
Compare
PR updated.
But squashed into one commit because of ^ this ^ |
[ERROR] [checkstyle] [ERROR] C:\projects\checkstyle\src\site\xdoc\checks\javadoc\javadocvariable.xml:241: Trailing whitespace is not allowed [noTrailingWhitespace] |
5c5ce75
to
5afb835
Compare
Before pushing, run on local |
5afb835
to
95174e0
Compare
Thanks, was testing locally but with the wrong goal (
|
Add to commit results on test execution, test phase generate actual xdoc pages |
95174e0
to
c28aff5
Compare
953eb04
to
2199c06
Compare
Not sure I follow, sorry? There were some checkstyle/CI issues with the docs I was unable to reproduce locally but all addressed now. |
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.
If you would like to add more text to website
Add it to https://github.com/checkstyle/checkstyle/blob/master/src/site/xdoc/checks/javadoc/javadocvariable.xml.template
Run tests, it will update xdoc file , add it to commit.
Items:
@@ -314,20 +314,27 @@ public static boolean isReceiverParameter(DetailAST parameterDefAst) { | |||
* @return the access modifier of the method/constructor. | |||
*/ | |||
public static AccessModifierOption getAccessModifierFromModifiersToken(DetailAST ast) { |
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.
This method is used in lot of Checks , lets not extend this fix to others
https://github.com/search?q=repo%3Acheckstyle%2Fcheckstyle%20getAccessModifierFromModifiersToken&type=code
Let's keep this fix isolated to single Check.
You can copy this util method to Check, and apply change to Check special method.
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.
This method is used in lot of Checks , lets not extend this fix to others https://github.com/search?q=repo%3Acheckstyle%2Fcheckstyle%20getAccessModifierFromModifiersToken&type=code
Let's keep this fix isolated to single Check. You can copy this util method to Check, and apply change to Check special method.
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 might be great miss in review of that PR.
If we change common method, now we need to re check all affected Checks that this new logic is good for them.
Most of them are not javadoc so, same though might be not applicable.
Javadoc check affected is only JavadocMethod.
https://checkstyle.org/checks/javadoc/javadocmethod.html
That use that same property.
Ok, lets do copy of method , keep in Until class, but new method will be used for javadoc only. In other case, we need to do diff testing for all affected Checks. I hope to do diff testing only for 2 javadoc Checks.
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 might be great miss in review of that PR.
If we change common method, now we need to re check all affected Checks that this new logic is good for them. Most of them are not javadoc so, same though might be not applicable.
I understand your concern, but those checks have already been affected in an unexpected way without checking.
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.
usage is big:
RecordComponentNumberCheck
UnusedLocalVariableCheck
ParameterNameCheck
JavadocVariableCheck
JavadocMethodCheck
and it might be concern for non-javadoc Check, as we are conflict of interpretation for javadoc and non-javadoc.
Functionality before this PR was focused on java only, and we naively thought that it will work for javadoc, that is why we have this issue.
Now we are clear that javadoc has nuance on it, and only javadoc related checks should be affected by this update.
does it make sense?
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.
We already can not predict and find by diff testinng ease sceanrios.
Whole reason of this issue exists, as we did not predicted it, diff showed nothing.
We can merge this, and in few moth one more person will be frustrated that we did not account him,
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.
Before this change, if I remember correctly, this method was raising an error as it could not evaluate the access modifier of an ENUM_CONSTANT_DEF. Based on that, I don't believe any other checks are affected, unless a scenario is not tested.
If I understand correctly, the conflict of opinions here is whether we should copy the method with the new changes to be used only for Javadoc checks, or update the existing method, which is used in a plethora of checks.
As I see it we could make a copy of the method for javadoc checks with the new updates, and revert the method to be used in other checks before these changes, this will probably satisfy both sides.
In my mind, it does not make a big difference, as the access modifier of ENUM_CONSTANT_DEF does not seem to be evaluated anywhere else apart from this check, but just to be safe, the approach of copy for javadoc and revert for the rest should be the safer option.
@romani @JackPGreen Did I get that correct? What do you think?
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.
As I see it we could make a copy of the method for javadoc checks with the new updates, and revert the method to be used in other checks before these changes, this will probably satisfy both sides.
In my mind, it does not make a big difference, as the access modifier of ENUM_CONSTANT_DEF does not seem to be evaluated anywhere else apart from this check, but just to be safe, the approach of copy for javadoc and revert for the rest should be the safer option.
@romani @JackPGreen Did I get that correct? What do you think?
I think adding another path with the previous undesirable behaviour just makes everything more complicated... but if it's two project maintainers vs one contributor I guess it is what it is.
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.
@JackPGreen , can you create new PR with split usage for method. Creation of new method might result in coverage problem, that might be not easy to cover, especially pitest.
But let give it a try, and we might be lucky. So we will have two PRs to merge one or another.
This PR is in good state, let's keep it without changes.
I will estimate risk vs efforts to make subjective decisions based on my experience.
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.
@JackPGreen , can you create new PR with split usage for method. Creation of new method might result in coverage problem, that might be not easy to cover, especially pitest.
But let give it a try, and we might be lucky. So we will have two PRs to merge one or another.
...mples/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocvariable/Example6.java
Outdated
Show resolved
Hide resolved
2199c06
to
a019bb4
Compare
Github, generate report for UnusedLocalVariable/all-examples-in-one |
Report for UnusedLocalVariable/all-examples-in-one: |
Github, generate report for ParameterName/all-examples-in-one |
Report for ParameterName/all-examples-in-one: |
Github, generate report for RecordComponentNumber/all-examples-in-one |
Report for RecordComponentNumber/all-examples-in-one: |
Github, generate report for JavadocVariable/all-examples-in-one |
Github, generate report for JavadocMethod/all-examples-in-one |
Report for JavadocVariable/all-examples-in-one: |
Report for JavadocMethod/all-examples-in-one: |
All reports are empty on diff except for JavadocVariable, JavadocVariable diff report looks good. The only concern is vague possibility on affecting other Checks, that is not common code at all, as we don't see it in diff. |
a019bb4
to
59d2702
Compare
Successor PR #17112 (comment) |
Extends change in #16049, in the case of an enum constant, it's accessibility will be derived based on the enclosing enum (which could be
private
) rather than being assumed to be implicitly public.Test(s) added to validate.
Fixes: #16786
Closes: #17112