[java] New rule UnnecessaryBoxing#3364
Conversation
This reverts commit d5c6cd0.
other 'unnecessary*' rule are there
Generated by 🚫 Danger |
adangel
left a comment
There was a problem hiding this comment.
👍
The following might be a false-positive:
return Integer.valueOf(matchValue).hashCode();
where matchValue is a primitive int field (https://github.com/checkstyle/checkstyle/blob/checkstyle-8.10/src/main/java/com/puppycrawl/tools/checkstyle/filters/IntMatchFilter.java#L50).
In order to call hashCode() we must wrap this int or use Integer.hashCode(matchValue) instead.... I guess, that's actually what should be done in that case, calling directly Integer.hashCode..., but it didn't come into my mind at first... Looking at the implementation, for integers hashcode is the integer value itself.... so technically you could also write here simply return matchValue.
Also I think, this violation is reported accidentally. But there are not many other methods, if any at all, where you need a wrapper object....
I'm inclined to accept this violation 😄
So, having this rule in PMD 7 means, we can deprecate the other rules (*Instantiation) but only in PMD 7, but still need to update the rules, so that they run in PMD 7. We can the finally remove the rules with PMD 8.
Hang on... confusing: So #3365 for PMD 6 will create a replacement for *Instantiation rules, so we can deprecate them with PMD 6 and remove them with PMD 7. Good.
So, this new rule "UnnecessaryBoxing" replaces actually just "UnnecessaryWrapperObjectCreation" (which is probably of no use anyway), right?
So technically, we need to update UnnecessaryWrapperObjectCreation for PMD 7, deprecate it there and remove it with PMD 8.
[java] New rule UnnecessaryBoxing #3364
Describe the PR
Add the new rule UnnecessaryBoxing, as per #2973. The old rules are not removed yet. We should have another rule that flags usages of primitive constructors actually (#3365).
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)