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

fix(S1481): add repair for enhanced for-loop #1033

Merged
merged 8 commits into from
May 4, 2023
Merged

Conversation

algomaster99
Copy link
Member

Fixes #1020

The issue has been there for quite some time. I had prepared a fix long ago, but SonarSource does not suggest it. I repaired the enhanced for-loop like so:

-        for (String input : inputList) { // noncompliant
+        for (int inputIterator=0; inputIterator < inputList.size(); ++inputIterator) { // compliant
            doSomething();
        }

For Collection, I use .size, and for arrays, I use .length.

I think this fix should be okay even though SonarSource does not suggest it. Do you have any opinions @Zuplyx and @khaes-kth against repairing something that SonarSource does not suggest?

@Zuplyx
Copy link

Zuplyx commented May 4, 2023

I've got no problems with this approach.

@algomaster99
Copy link
Member Author

They claim that such code is indeed a non-compliant. However, they do not suggest a quick fix for this. Moreover, they explicitly say that they have a partial quick fix for it. I think it is okay if we repair it.

@khaes-kth
Copy link
Collaborator

@algomaster99
It seems reasonable to me as we.

@algomaster99 algomaster99 merged commit 036c965 into master May 4, 2023
@algomaster99 algomaster99 deleted the fix-S1481 branch May 4, 2023 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Bug in S1481
3 participants