Skip to content
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

Method visibility rule is too aggressive classes nested in intefaces #140

Closed
vpavic opened this issue Sep 10, 2019 · 3 comments
Closed

Method visibility rule is too aggressive classes nested in intefaces #140

vpavic opened this issue Sep 10, 2019 · 3 comments
Milestone

Comments

@vpavic
Copy link
Contributor

vpavic commented Sep 10, 2019

While trying to align Spring Session with Spring Java Format 0.0.15 I've found the newly introduced method visibility rule (introduced in #128) to be too aggressive.

For instance, this rule errors out due to methods of Spring Session's CookieSerializer.CookieValue being public. Complying with this would be a breaking API change. This is quite dangerous for a default check.

Another example are @Bean factory methods on (typically static and package-private) inner @Configuration classes as those are no longer allowed to be public. Personally I'd prefer to have all @Bean factory methods public (possibly due to still having the old behavior in the back of my head - see spring-projects/spring-framework#11829) and find this a bit too prescriptive for being among default checks.

With that in mind, my proposal is to remove method visibility rule from automatically applied checks, and have it enabled manually in projects that prefer it, like Spring Boot. Otherwise I feel it greatly impacts the adoption of this project across Spring projects.

@philwebb
Copy link
Contributor

The issue with CookieSerializer.CookieValue looks like a bug because we're not considering it a public class and we should be. We've got another one of those in #132.

As for changing the default, I'm not totally convinced that we should drop the rule, but I'd like to see what the rest of the team think. We found it identified a few placed in Spring Boot where we were accidentally has a package private classes in the API that should have been public.

It's pretty easy to add a <suppress files=".*" ... rule in the meantime if you want to just suppress it for all files.

@vpavic
Copy link
Contributor Author

vpavic commented Sep 10, 2019

Thanks for the quick feedback.

Yeah, the rule certainly does have some value. If first situation is a bug, and second one can be handled nicely somehow, I'd leave it enabled by default.

What's your take on @Bean factory method visibility remark? IMO it's valid to have those with same visibility across the project.

@wilkinsona
Copy link
Contributor

I'd prefer not to drop the rule as well. As another data point, I adopted it in Spring REST Docs with minimal hassle.

FWIW, I think @Bean methods should be treated the same as any other method and, therefore, their visibility should be minimised.

@philwebb philwebb changed the title Method visibility rule is too aggressive Method visibility rule is too aggressive classes nested in intefaces Dec 3, 2019
@philwebb philwebb added this to the 0.0.16 milestone Dec 3, 2019
@philwebb philwebb modified the milestones: 0.0.16, 0.0.17 Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants