Skip to content

Issue #14654: fix catch parameter wrong indentation #16627

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

Merged
merged 1 commit into from
May 8, 2025

Conversation

mohitsatr
Copy link
Member

@mohitsatr mohitsatr commented Mar 22, 2025

@mohitsatr
Copy link
Member Author

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

Copy link
Contributor

@romani
Copy link
Member

romani commented Mar 22, 2025

do not forget to add code to ITs of google style, to let formatter do formatting on code and checkstyle run on same file.

./.ci/google-java-format.sh .ci-temp/google-java-format-${{env.VERSION}}-all-deps.jar

be aware of files that are excluded due to conflict of formatter and checkstyle:

| grep -v "rule42blockindentation/ClassWithChainedMethods.java" \

if you put a lot of samples to ITs of google it will be good prove that formatter and checkstyle validate same code and not conflicting with each other

@mohitsatr
Copy link
Member Author

Github, generate report

1 similar comment
@mohitsatr
Copy link
Member Author

Github, generate report

Copy link
Contributor

@romani
Copy link
Member

romani commented Mar 27, 2025

@mohitsatr , is it still wip ?

@mohitsatr
Copy link
Member Author

yes, I was busy researching for proposal. i will get to back to it as soon as Im done with that

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch from 8ead1b4 to 81073fc Compare April 15, 2025 10:32
@mohitsatr
Copy link
Member Author

@Zopsss @romani ready for review

@mohitsatr
Copy link
Member Author

Github, generate report

Copy link
Contributor

@mohitsatr
Copy link
Member Author

nevermind, I'm checking the diffs

@mohitsatr
Copy link
Member Author

there are conflicts created by the google-formatter.

   public void test1() {
     try {
       System.out.println("try0");
     } catch (NullPointerException
-| IllegalArgumentException t) { // violation '.* incorrect indentation level 0, expected .* 8.'
+        | IllegalArgumentException
+            t) { // violation '.* incorrect indentation level 0, expected .* 8.'
     }
   }

even though I have specified wrong indentation in violation message, it thinks code's formatted wrong.

        System.out.println("try");
     } catch (
         @SuppressWarnings("PMD.AvoidCatchingGenericException")
-    Exception e) { // violation '.* incorrect indentation level 4, expected .* 8.'
+        Exception e) { // violation '.* incorrect indentation level 4, expected .* 8.'
       java.util.logging.Logger.getAnonymousLogger().severe(e.toString());
     }

@mohitsatr
Copy link
Member Author

@romani @Zopsss please review

@romani
Copy link
Member

romani commented Apr 20, 2025

google formatter is more strict and opinionated.
Please apply patch from google formatter, our goal is to not put violation that what google formatter say is good.

in regular test area Inputs we can have any crazy indentations and see how Check place violation on it.

in IT for google style, we apply auto-formatter first, and must not produce any violation on what formatter did with code.
There might some defects in formatter also, and we should report to them and we will think what to do.

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch from 81073fc to 193d44d Compare April 21, 2025 07:12
@romani
Copy link
Member

romani commented Apr 22, 2025

formatter is still red, please fix.

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch 2 times, most recently from 262b27f to 501aa8d Compare April 23, 2025 08:06
@mohitsatr
Copy link
Member Author

mohitsatr commented Apr 23, 2025

I suppose pitest one is not related to my changes?
can you please review the diff report
#16627 (comment)

@Zopsss
Copy link
Member

Zopsss commented Apr 24, 2025

Yes it is not related to your PR.

@romani romani force-pushed the indent-catch-parameter branch from 501aa8d to 7d8f4ef Compare April 26, 2025 15:53
@romani
Copy link
Member

romani commented Apr 26, 2025

from semaphore:
https://checkstyle.semaphoreci.com/jobs/a7fb1b76-14ec-4825-9c9d-30672bee1b69#L836

> Task :postgresql:checkstyleMain 04:22
[ant:checkstyle] [ERROR] /home/semaphore/checkstyle/.ci-temp/pgjdbc/pgjdbc/src/main/java/org/postgresql/util/PasswordUtil.java:69:9: 'try' child has incorrect indentation level 8, expected level should be 10. [Indentation] 04:22
[ant:checkstyle] [ERROR] /home/semaphore/checkstyle/.ci-temp/pgjdbc/pgjdbc/src/main/java/org/postgresql/util/PasswordUtil.java:70:9: 'try' child has incorrect indentation level 8, expected level should be 10. [Indentation] 04:22
[ant:checkstyle] [ERROR] /home/semaphore/checkstyle/.ci-temp/pgjdbc/pgjdbc/src/main/java/org/postgresql/util/PasswordUtil.java:71:9: 'try' child has incorrect indentation level 8, expected level should be 10. [Indentation] 04:22
[ant:checkstyle] [ERROR] /home/semaphore/checkstyle/.ci-temp/pgjdbc/pgjdbc/src/main/java/org/postgresql/util/PasswordUtil.java:72:9: 'try' child has incorrect indentation level 8, expected level should be 10. [Indentation]

if this is are not false positives, please send PR to pgjdbc to fix them to make CI green fully (after they merge).

execution from:

no-error-pgjdbc)
CS_POM_VERSION="$(getCheckstylePomVersion)"
echo CS_version: "${CS_POM_VERSION}"
mvn -e --no-transfer-progress clean install -Pno-validations
echo "Checkout target sources ..."
checkout_from https://github.com/pgjdbc/pgjdbc.git
cd .ci-temp/pgjdbc
./gradlew --no-parallel --no-daemon checkstyleAll \
-PenableMavenLocal -Pcheckstyle.version="${CS_POM_VERSION}"
cd ../
removeFolderWithProtectedFiles pgjdbc
;;

target code looks ok:
https://github.com/pgjdbc/pgjdbc/blob/1e0c88d8bb292417f499d9a4821af67fc5740966/pgjdbc/src/main/java/org/postgresql/util/PasswordUtil.java#L60-L76
it looks like false positive, but it is actually good vioaltions, as it is line wrap on statement inside try not a try itself.

please sen PR to pgjdbc

@sdavids
Copy link

sdavids commented Apr 26, 2025

Just a small nitpick:

parameters is not spelled correctly in the commit message

@mohitsatr
Copy link
Member Author

please sen PR to pgjdbc

done pgjdbc/pgjdbc#3611

Copy link
Contributor

@romani
Copy link
Member

romani commented Apr 30, 2025

Ok, reports are same, let's extend Inputs and be prepared for merge

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch from 7d8f4ef to 0198e5f Compare May 1, 2025 04:51
@romani
Copy link
Member

romani commented May 1, 2025

@mohitsatr , CI is red, please address.

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch 2 times, most recently from 00f269a to aeb481c Compare May 3, 2025 03:31
Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Items

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch from aeb481c to 701b911 Compare May 3, 2025 05:56
@mohitsatr
Copy link
Member Author

I don't understand why javac11 is failing even though javac17 has passed successfully.

@romani
Copy link
Member

romani commented May 3, 2025

jdk version matters a lot, this syntax is for jdk17

src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationMultilineStatements.java:56: error: unclosed string literal
    final String simpleProperty = """
                                    ^

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

item:

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch from 701b911 to d39ee66 Compare May 3, 2025 13:47
Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

thanks a lot !!!

@Aziz-755, can you review this PR ?

Copy link
Contributor

@Aziz-755 Aziz-755 left a comment

Choose a reason for hiding this comment

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

Great work!
Just minors

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Items

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch from d39ee66 to f98ed1d Compare May 7, 2025 03:47
@romani
Copy link
Member

romani commented May 7, 2025

Github, generate report

Copy link
Contributor

github-actions bot commented May 7, 2025

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

last items:

try { //indent:4 exp:4
System.out.println("try"); //indent:6 exp:6
} catch ( //indent:4 exp:4
@SuppressWarnings("PMD.AvoidCatchingGenericException") //indent:12 exp:8 warn
Copy link
Member

Choose a reason for hiding this comment

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

please fix vertical alignment of trailing comment

Copy link
Member Author

Choose a reason for hiding this comment

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

done all.
just curious, can we somehow automate alignment of comments? it's quite tedious doing manually 🥲

try { //indent:4 exp:4
System.out.println("try0"); //indent:6 exp:6
} catch (NullPointerException //indent:4 exp:4
| IllegalArgumentException t) { //indent:0 exp:8 warn
Copy link
Member

Choose a reason for hiding this comment

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

please fix vertical alignment of trailing comment

@@ -0,0 +1,82 @@
//non-compiled with javac: Compilable with Java17 //indent:0 exp:0
package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0
Copy link
Member

Choose a reason for hiding this comment

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

please fix vertical alignment of trailing comment

try { //indent:4 exp:4
System.out.println("try1"); //indent:6 exp:6
} catch ( //indent:4 exp:4
@SuppressWarnings("PMD.AvoidCatchingGenericException") //indent:4 exp:8 warn
Copy link
Member

Choose a reason for hiding this comment

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

please fix vertical alignment of trailing comment

System.out.println("try"); //indent:6 exp:6
} catch ( //indent:4 exp:4
@SuppressWarnings("PMD.AvoidCatchingGenericException") //indent:8 exp:8
Exception e) { //indent:4 exp:8 warn
Copy link
Member

Choose a reason for hiding this comment

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

please fix vertical alignment of trailing comment

@romani
Copy link
Member

romani commented May 7, 2025

@Aziz-755 , please finalize review.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

last last:

1;
}

int testIfConditionMultiline(int newState, int tableName) { //indent:2 exp:2
Copy link
Member

Choose a reason for hiding this comment

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

please remove trailing comment

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

diff report is good.
thanks a lot for your hard work!!!

@Aziz-755
Copy link
Contributor

Aziz-755 commented May 7, 2025

Looks good !

@mohitsatr mohitsatr force-pushed the indent-catch-parameter branch from f98ed1d to 048fc8f Compare May 8, 2025 02:56
Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Thanks a lot!!!!

just curious, can we somehow automate alignment of comments? it's quite tedious doing manually 🥲

Please create issue on this, it should be trivial, we parsing this comment, so we definitely know it's position, but there might be exceptions.

@romani romani merged commit edbfc66 into checkstyle:master May 8, 2025
117 checks passed
@mohitsatr mohitsatr deleted the indent-catch-parameter branch May 8, 2025 12:17
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.

incompatibility with google-java-format: CatchFormalParameter is indented by 4 spaces instead of 2
5 participants