rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

RSPEC-2864 - entrySet()" should be iterated when both the key and value are needed

Open blipper opened this issue 1 year ago • 2 comments

Describe the situation before applying the recipe

See https://rules.sonarsource.com/java/RSPEC-2864/

Describe the situation after applying the recipe

Have you considered any alternatives or workarounds?

Any additional context

This is a SpotBugs error https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#wmi-inefficient-use-of-keyset-iterator-instead-of-entryset-iterator-wmi-wrong-map-iterator

https://github.com/spotbugs/spotbugs/blob/d999c35c134f5310b688f2b4513e3689fb1439bc/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/WrongMapIterator.java#L256

Test cases here https://github.com/spotbugs/spotbugs/blob/d999c35c134f5310b688f2b4513e3689fb1439bc/spotbugsTestCases/src/java/WMITest.java#L10

Are you interested in contributing this recipe to OpenRewrite?

blipper avatar Oct 12 '24 19:10 blipper

Thanks for the helpful example links; indeed would be a neat addition to see this fixed with a recipe.

timtebeek avatar Oct 15 '24 11:10 timtebeek

This issue is stale because it has not had any activity for 60 days. Remove question label or comment or this will be closed in two weeks. Issues may be reopened when there is renewed interest.

github-actions[bot] avatar Jul 28 '25 11:07 github-actions[bot]