Skip to content

Issue #18118: fix indentation calculation logic for chained method call#18406

Merged
romani merged 1 commit into
checkstyle:masterfrom
M-SaaD-H:18118
Jan 30, 2026
Merged

Issue #18118: fix indentation calculation logic for chained method call#18406
romani merged 1 commit into
checkstyle:masterfrom
M-SaaD-H:18118

Conversation

@M-SaaD-H

@M-SaaD-H M-SaaD-H commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

Fixes #18118

Problem
The Indentation check incorrectly flagged the closing parenthesis in chained method calls like:

List.of("foo").stream()
    .findFirst()
    .ifPresentOrElse(
        System.out::println,
        () -> { throw new IllegalStateException(); }
    );  // False positive: expected level 8, but 12 is correct

However, using Stream.of("foo") instead produced no error, creating inconsistent behavior.

Solution
Modified MethodCallHandler.getIndentImpl() to add the line start column as an acceptable+ indent level for chained method calls. This allows correctly indented closing parens to be accepted while still validating actually incorrect indentation.

@Atharv3221

Copy link
Copy Markdown
Contributor

Github, generate report for Indentation/all-examples-in-one

@Atharv3221

Copy link
Copy Markdown
Contributor

@romani
This change fixes #17685

@github-actions

Copy link
Copy Markdown
Contributor

@Atharv3221

Copy link
Copy Markdown
Contributor

Diff is huge

@M-SaaD-H

Copy link
Copy Markdown
Contributor Author

Hi @Atharv3221 ,
Thanks for pointing that out.
Yes, both these issues arise from the same underlying cause. I raised this PR against the original issue (18118). But it should also address the second issue (17685). Should I just mention this one in the description of this PR or the second issue needs to be addressed in a new PR?

@Atharv3221

Copy link
Copy Markdown
Contributor

As per regression report change has caused huge difference in reported violations. I don't think all violations change were false positives. Means fix wasn't proper. Please add a test case which fails from this change.

@M-SaaD-H M-SaaD-H force-pushed the 18118 branch 3 times, most recently from a0ec879 to 17a959d Compare December 25, 2025 09:08
@M-SaaD-H

Copy link
Copy Markdown
Contributor Author

Github, generate report for Indentation/all-examples-in-one

@github-actions

Copy link
Copy Markdown
Contributor

@M-SaaD-H

Copy link
Copy Markdown
Contributor Author

Hi @Atharv3221
I have added the test for this fix and generated the report. Can you please look into it?
Let me know if you need anything from my side.

@Atharv3221

Copy link
Copy Markdown
Contributor

@M-SaaD-H
red one are the violation messages which were removed after the change and green one are added after change you can check the code its tested against by line number ahead.

@M-SaaD-H

Copy link
Copy Markdown
Contributor Author

@Atharv3221
I reviewed the diff regression report for some of the projects. The added violations correspond to real cases in the affected files and are expected behavior for this check.

@romani

romani commented Dec 30, 2025

Copy link
Copy Markdown
Member

rebased in web

@romani

romani commented Dec 30, 2025

Copy link
Copy Markdown
Member

@M-SaaD-H M-SaaD-H force-pushed the 18118 branch 5 times, most recently from fbb84a3 to bfd4287 Compare January 2, 2026 08:49
@M-SaaD-H

M-SaaD-H commented Jan 2, 2026

Copy link
Copy Markdown
Contributor Author

@romani
Added the required inputs.

@M-SaaD-H

M-SaaD-H commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

@romani
The CI failure is due to a 403 while resolving org.sonatype.oss:oss-parent:9 from Maven Central in GitHub Actions. The same dependency resolves successfully locally, so this appears to be a CI/network issue. Could you please take a look?

@M-SaaD-H M-SaaD-H force-pushed the 18118 branch 2 times, most recently from d57a852 to 50fb25a Compare January 7, 2026 15:22
@M-SaaD-H

M-SaaD-H commented Jan 9, 2026

Copy link
Copy Markdown
Contributor Author

@romani
All CIs are passing now.

@romani

romani commented Jan 10, 2026

Copy link
Copy Markdown
Member

Github, generate report for Indentation/all-examples-in-one

@github-actions

Copy link
Copy Markdown
Contributor

@M-SaaD-H

M-SaaD-H commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

@romani
The failing CI is showing the following error. It is failing due to failure to parse the .ci/pitest-survival-check-xml.groovy file. I have seen some other PRs too, they shows the same warning, but this one fails due to GitHub actions timout (10min).

[WARNING] There were problems parsing .ci/pitest-survival-check-xml.groovy
[WARNING] org.openrewrite.groovy.GroovyParsingException: Failed to parse .ci/pitest-survival-check-xml.groovy at cursor position 11283. The surrounding characters in the original source are:
al Set result = new TreeSet<>(setOne)
result.removeIf { mutation -> setTwo.contains(mutation) }
return result
}

 /**
 * A class to represent the XML {@code mutation} node.
*/
@EqualsAndHashCode(excludes = ["lineNumber", "unstable"]~cursor~>)
@Immutable
class Mutation implements Comparable<Mutation> {

    /**
     * Mutation nodes present in suppressions file do not have a {@code lineNumber}.
     * The {@code lineNumber} is set to {@code -1} for such mutations.
     */
    private sta
  org.openrewrite.groovy.GroovyParserVisitor.visit(GroovyParserVisitor.java:209)

[INFO] Running recipe(s)...

Too long with no output (exceeded 10m0s): context deadline exceeded

@romani

romani commented Jan 10, 2026

Copy link
Copy Markdown
Member

@M-SaaD-H , please review diff report, too much changes, we need to be sure that no regressions happening

@romani

romani commented Jan 10, 2026

Copy link
Copy Markdown
Member

@vivek-0509, please help to review this PR. You are expert in this Check.

@vivek-0509

Copy link
Copy Markdown
Member

Sure, I’ll review it once I get back to my laptop.

@vivek-0509

Copy link
Copy Markdown
Member

Github, generate report for Indentation/all-examples-in-one

@github-actions

Copy link
Copy Markdown
Contributor

Report generation failed. Please check the logs for more details.

Link: https://github.com/checkstyle/checkstyle/actions/runs/20986984251

@vivek-0509

Copy link
Copy Markdown
Member

Github, generate report for Indentation/all-examples-in-one

@github-actions

Copy link
Copy Markdown
Contributor

@vivek-0509

vivek-0509 commented Jan 14, 2026

Copy link
Copy Markdown
Member

@romani
Ok to merge from my side, the suggested approach (#18406 (comment)) works as expected no regression caused.
https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/47af876bed69675e8dc528ab2a87341522980fcb_2026112613/reports/diff/index.html

@vivek-0509

Copy link
Copy Markdown
Member

@M-SaaD-H We found a new surviving mutant please eliminate it

+  <mutation unstable="false">
+    <sourceFile>MethodCallHandler.java</sourceFile>
+    <mutatedClass>com.puppycrawl.tools.checkstyle.checks.indentation.MethodCallHandler</mutatedClass>
+    <mutatedMethod>checkRparenIndent</mutatedMethod>
+    <mutator>org.pitest.mutationtest.engine.gregor.mutators.MathMutator</mutator>
+    <description>Replaced integer addition with subtraction</description>
+    <lineContent>if (rparenLevel != lparenLevel + 1</lineContent>
+  </mutation>

@M-SaaD-H

Copy link
Copy Markdown
Contributor Author

@vivek-0509 @romani
Mutant eliminated.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot !!!

@romani romani merged commit ddc7211 into checkstyle:master Jan 30, 2026
119 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent behaviour of Indentation check

4 participants