Skip to content

Issue #14963: Add new property to skip unnamed parameters in FinalPar…#15166

Merged
rnveach merged 1 commit into
checkstyle:masterfrom
checkstyle-GSoC25:finalparameters
Jul 2, 2024
Merged

Issue #14963: Add new property to skip unnamed parameters in FinalPar…#15166
rnveach merged 1 commit into
checkstyle:masterfrom
checkstyle-GSoC25:finalparameters

Conversation

@mahfouz72

Copy link
Copy Markdown
Member Author

github, generate report

@mahfouz72

Copy link
Copy Markdown
Member Author

github, generate site

@github-actions

Copy link
Copy Markdown
Contributor

@mahfouz72

Copy link
Copy Markdown
Member Author

github, generate report

@github-actions

Copy link
Copy Markdown
Contributor

@mahfouz72

mahfouz72 commented Jun 29, 2024

Copy link
Copy Markdown
Member Author

https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/e53d9a2_2024010200/reports/diff/checkstyle/index.html#A3 This exception due to record pattern syntax in enhanced for that is no longer compilable syntax. It was in preview and removed in the final release


PS D:\CS\test> cat src/Test.java
import java.util.List;

public class Test {
    void test(Object o) {
        List<Point> points = List.of(new Point(1, 2), new Point(3, 4), new Point(5, 6));
        for (Point(int x, int y): points) {} // Record patterns in for-each loops are not supported at language level '22'
    }
    record Point(int x, int y) { }
}
PS D:\CS\test> javac src/Test.java
src\Test.java:6: error: '.class' expected
        for (Point(int x, int y): points) {} 
                       ^
src\Test.java:6: error: ';' expected
        for (Point(int x, int y): points) {}
                        ^
src\Test.java:6: error: '.class' expected
        for (Point(int x, int y): points) {}
                              ^
src\Test.java:6: error: not a statement
        for (Point(int x, int y): points) {}
                          ^
src\Test.java:6: error: ';' expected
        for (Point(int x, int y): points) {}
                               ^
src\Test.java:6: error: not a statement
        for (Point(int x, int y): points) {}
                                  ^
src\Test.java:6: error: ';' expected
        for (Point(int x, int y): points) {}
                                        ^
7 errors

@nrmancuso

Copy link
Copy Markdown
Contributor

https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/e53d9a2_2024010200/reports/diff/checkstyle/index.html#A3 This exception due to record pattern syntax in enhanced for that is no longer compilable syntax. It was in preview and removed in the final release

Please always show this sort of thing via javac.

@nrmancuso nrmancuso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, one item:

@nrmancuso nrmancuso self-assigned this Jun 29, 2024
@mahfouz72

Copy link
Copy Markdown
Member Author

github, generate site

@mahfouz72

Copy link
Copy Markdown
Member Author

github, generate site

@nrmancuso nrmancuso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Last item:

@mahfouz72 mahfouz72 force-pushed the finalparameters branch 2 times, most recently from 58f6523 to 8c1ae7b Compare June 30, 2024 22:32
@nrmancuso nrmancuso requested a review from rnveach July 1, 2024 11:42
@nrmancuso nrmancuso assigned rnveach and unassigned nrmancuso Jul 1, 2024
@mahfouz72 mahfouz72 force-pushed the finalparameters branch 2 times, most recently from 606e04d to 3903933 Compare July 1, 2024 12:27
Comment thread src/xdocs/checks/misc/finalparameters.xml Outdated
Comment thread src/xdocs/checks/misc/finalparameters.xml
@rnveach

rnveach commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

@romani @nrmancuso
https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/e53d9a2_2024010200/reports/diff/checkstyle/index.html#A3
https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/e53d9a2_2024010200/reports/diff/checkstyle/index.html#A8
https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/e53d9a2_2024010200/reports/diff/checkstyle/index.html#A10
Regression found an exception.

@mahfouz72 Move exception in master to new issue. Our checks should not throw an exception on compilable code.

Edit:
#15166 (comment)

This exception due to record pattern syntax in enhanced for that is no longer compilable syntax. It was in preview and removed in the final release

If it is no longer compilable, why is it still in our repo and still marked as compilable ("Compilable with Java20")? Is this also something we should discuss removing?

@rnveach

rnveach commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

Maybe I am not finding all the regressions. I should see regression of:

  • Base is default with all tokens, Patch is default with ignoreUnnamedParameters set to true with all tokens (expecting unnamed differences only)
  • Base is default with all tokens, Patch is default with ignoreUnnamedParameters set to false with all tokens (expecting no differences)

@mahfouz72

mahfouz72 commented Jul 1, 2024

Copy link
Copy Markdown
Member Author

If it is no longer compilable, why is it still in our repo and still marked as compilable ("Compilable with Java20")? Is this also something we should discuss removing?

I suggested somewhere that we should open an issue to remove the no longer compilable code in our repo. Such code was a preview in some version we supported it but it was removed. So I am good with this as an issue

Edit: I remembered @nrmancuso said as long as we support some syntax it should have an input file. #14961 (comment)

@mahfouz72

Copy link
Copy Markdown
Member Author

github, generate report

@github-actions

github-actions Bot commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

@mahfouz72

Copy link
Copy Markdown
Member Author

github, generate report

@github-actions

github-actions Bot commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

@rnveach

rnveach commented Jul 2, 2024

Copy link
Copy Markdown
Contributor

https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/22a829d_2024194022/reports/diff/index.html
Change in exceptions is fine. I am asking more questions outside of this.

https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/22a829d_2024183400/reports/diff/index.html

https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/22a829d_2024183400/reports/diff/openjdk17/index.html#A2
This is an interesting case. Method parameters can't be unnamed, but this file isn't compilable. Pre-java 9 they could use _ as a named method parameter. Point of ignoring property is for Java 21+ projects to use and like I said they can't have a unnamed method parameter, so this behavior seems ok to me.

@rnveach rnveach merged commit 4fbbc55 into checkstyle:master Jul 2, 2024
@mahfouz72 mahfouz72 deleted the finalparameters branch May 9, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: FinalParameter

3 participants