You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] Fix ClassCastException in UnnecessaryLocalBeforeReturn - #221
@adangel I think we should consider several changes to this rule. Please let me know what you think and We can add issues to track each individually.
This should probably be moved from the design ruleset to the unnecessary ruleset.
We should probably drop the requirement for the declaration and the return being in consecutive lines, and simply check the number of uses of the variable being > 1. This also means no need for the current assert lookup.
Given that we actually do item 2, this rule could be expanded to all "unnecessary" variables, not just return statements. We could add a property to allow such variables if declared as final. The Java code will produce an extra store / load instruction in bytecode, but being final, the JIT will remove them and effectively be the same for long running processes.
yes - I myself first searched this rule first in the unnecessary ruleset. This would be a change for master branch / 5.6.x, to avoid surprises if the rule suddenly pops up / disappears.
This definitely makes sense and would be an enhancement for 5.5.x
I would see this for the master branch (maybe even for 5.5.x, too). We could basically create a successor rule "UnnecessaryLocal" and retire "UnnecessaryLocalBeforeReturn". Sounds like the DeadStore rule from FindBugs...
Yes, but without the false positives introduced by javac:
Note that Sun's javac compiler often generates dead stores for final local variables. Because FindBugs is a bytecode-based tool, there is no easy way to eliminate these false positives
Doing 2 and 3 makes no sense if both are merged into 5.5.5 and we retire UnnecessaryLocalBeforeReturn. Being 5.5.5 a bug fixing release I'd not be comfortable retiring a rule in it. Either we leave it as deprecated for a while (5.6.0 or 5.7.0?), or we should do only item 2 for 5.5.5 and the new rule for 5.6.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.