Update checkstyle and fix violations#20909
Conversation
|
I'll reviewing it. I like boring PRs while drinking coffee in the morning. |
I think if we think our reasons are good we should pop over to the checkstyle project and file an issue asking to be able to disable that portion of the check. Is our reason that we want implementers to declare those parameters final and we like that IDEs do that by default if the parameters are final in the interfaces? Beyond that I can't think of any reason to declare parameters on interface methods final. |
| httpServer.createContext("/" + pathPrefix + statusCode + uniqueContextSuffix, new ResponseHandler(statusCode)); | ||
|
|
||
| try (final RestClient client = | ||
| try (RestClient client = |
There was a problem hiding this comment.
I'd never really thought of this but it makes sense.
Yes, this is the "good reason" I'm talking about. I didn't check every place but each time such a violation was reported I found a good reason to let the
Makes sense. |
nik9000
left a comment
There was a problem hiding this comment.
All the code changes look good to me. They fall into three categories:
publicmethods on non-publicclasses don't make sense. Remove the modifier and let the method inherit the modifier.- try-with-resources variables should not be declared
finalbecause they are implicitlyfinal.finaladds no extra information for the reader. I guess that makes them names rather than variables.... enums are alwaystaticso there is no need to declare themstatic.finaldoesn't do anything on anonymous classes because they can't be extended anyway. So we just remove the modifier.- Classes declared inside of interfaces are always
staticso we shouldn't also declare them asstatic.
Personally I'm not sure that "because implementers should declare them |
|
Question: why do we have all these violations to fix just because we are upgrading checkstyle? Did the set of applied rules change as well? This all makes sense (I was tired too of seeing all these warnings in my IDE) but it would be good (for next time) to do one category at a time maybe? Can we also update the description of the PR with the nice summary that Nik posted? |
The meaning of the |
Not really the set of rules but rather the way the rule are working.
Sadly we can't because we can't really configure the granularity of the checks.
Sure, I should have done that. |
Maybe we could have fixed the issues one category at a time before updating checkstyle for instance? Not sure though. Anyways, thanks for fixing these! |
Yeah, we certainly could have. If these changes hadn't been super mechanical stuff I could review while leisurely sipping coffee I'd have asked for that. And we should totally keep that as an option for next time! |
|
Closed in favor of #22960 |
This PR updates the version of Checkstyle from current
5.9to7.1and fix a bunch of new violations.A more recent version would allow us to use some new checkstyle modules (like Javadocs).
RedundantModifieris improved and now detects more violations that are fixed by this PR. The changes fall into three categories (thanks @nik9000 for the nice summary):publicmethods on non-publicclasses don't make sense. Remove the modifier and let the method inherit the modifier.finalbecause they are implicitlyfinal.finaladds no extra information for the reader. I guess that makes them names rather than variables....enums are alwaystaticso there is no need to declare themstatic.finaldoesn't do anything on anonymous classes because they can't be extended anyway. So we just remove the modifier.staticso we shouldn't also declare them asstatic.For the record, most of the changes were automated using this small Bash script:
Checkstyle was not updated to the latest version 7.1.2 because it reports violations for
finalparameters in interface methods (checkstyle/checkstyle#3322) and we have a lot of these for good reason.I'm really sorry for the boringness of this kind of pull request.