Repository navigation
Issue #20339 fix: use expandedTabsColumnNo in NewHandler.getIndentImpl for tab sup… - #20342
Conversation
74f1f57 to
4daa0ad
Compare
|
@romani Hi! Since this is my first contribution to Checkstyle, my CI workflows are pending manual approval. Could you please help trigger the runs when you have a moment? I've verified the tests locally. Thanks! |
0e7ac17 to
1c1ae3a
Compare
|
@Atharv3221 Done, added two test cases: testNewKeywordWithTab — non-strict mode, new at the first nesting level |
|
Github, generate report for Indentation/Example1 |
|
@BobSong-dev , according to issue, only tab based files should be affected, but diff reprot shows more changes. please review all, and improve code if you see some false positives |
This update mainly includes two adjustments. The previous change fixed the false positive reported in #20339, but its impact was broader than intended. It changed the indentation calculation whenever The condition has now been narrowed. The line-start indentation logic is used only when both the raw column and the tab-expanded column confirm that I also updated the tests. The previous tests only covered a single-line expression: Object obj = new Object();Those tests passed even with the original implementation, so they did not actually reproduce the reported issue. The new tests use the multiline constructor case from the issue: throw new RuntimeException(
"Exception");Both strict and non-strict configurations are now covered. I ran the relevant tests as well as the full Feedback and corrections are very welcome. |
b629813 to
56546a0
Compare
this is a big concern, as users wihtout tabs, majority of codebases will get false-positives. please add to our Inputs this snippet with violation asd fixed form of it https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/1c1ae3aec5d09ffb34fb5490ab42d29c45f19ae8_2026232108/reports/diff/java-design-patterns/index.html#A1 and https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/1c1ae3aec5d09ffb34fb5490ab42d29c45f19ae8_2026232108/reports/diff/spring-framework/index.html#A1 |
56546a0 to
f0558e9
Compare
6e5a633 to
2a18cff
Compare
|
ok ,thanks a lot, it looks like we resolved few other problems :) by this tab issue. |
|
@BobSong-dev , pelase glance at https://github.com/checkstyle/checkstyle/issues?q=is%3Aissue%20state%3Aopen%20label%3Aindentation do you see any issue that you resovled by your update ? |
Thanks! I checked the advanced CI. The functional checks look good, including the indentation tests and the test-resources compilation check. The only red job is the Java performance check. It looks like the run was faster than the baseline, but the performance threshold was still exceeded. The javadoc job was cancelled as a result. AppVeyor is still running. I also checked the open indentation issues, and this change seems to resolve #18614 as well as #20339. I reproduced the tab-indented cases from #18614 with the current PR. The correctly indented constructor arguments inside The root cause appears to be the same raw-column versus tab-expanded-column mismatch in |
|
ok, please add users code from #18614 to Input to make sure it is fixed. But all such issues are from same Author and with TAB usage. https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/1c1ae3aec5d09ffb34fb5490ab42d29c45f19ae8_2026232108/reports/diff/spoon/index.html#A1 Looks like we affected Lets take https://github.com/SpigotMC/BungeeCord project, looks like it uses default Indentation and enforce no error. |
… indentation in NewHandler
2a18cff to
326bf1e
Compare
|
GitHub, generate report |
|
Done, thanks. I completed the requested follow-up:
The BungeeCord report completed with 0 differences: |
The Semaphore failure appears unrelated to this PR. The external The local full verification passes, and the BungeeCord diff report has |
|
Semaphore got regression cause by previos PRs, CI is very unstable today .... that is why we got leak . |
Fixes #20339
Closes #18614
Hi, thanks for maintaining Checkstyle. I took a look at the false positive reported in #20339 and found the root cause.
Problem
In
NewHandler.getIndentImpl()line 124, the code checks ifnewis at the start of a line:getLineStart()returns the tab-expanded column, butgetColumnNo()returns the raw column. With tab-indented files these two values don't match, even whennewis actually the first non-whitespace character on the line.For example, with
tabWidth=4and 2 tabs of indentation,getLineStart()returns 8 whilegetColumnNo()returns 2, so the check wrongly evaluates tofalse.The reverse case is also broken: when
newis NOT at the line start (e.g. afterthrow), the raw column can coincidentally equal the line start, producing a falsetrue.Fix
Replace
mainAst.getColumnNo()withexpandedTabsColumnNo(mainAst)— the same pattern already used byisOnStartOfLine()at line 180 of the same file, and consistent with the fix in PR #18686.Additional note
While investigating, I noticed
MethodCallHandler.javaline 185 has the same pattern:This would have the same tab-related issue. I kept this PR focused on
NewHandleras described in the issue, but wanted to flag it for awareness.Test
Added two test cases in
IndentationCheckTest.javawith corresponding input files:testNewKeywordWithTab— non-strict mode (forceStrictCondition=false),newat the first nesting level with tab indentationtestNewKeywordWithTabStrict— strict mode (forceStrictCondition=true),newinside an if block (deeper nesting) with tab indentationBoth input files use actual tab characters for indentation. Before the fix these would produce false positives; after the fix no warnings are expected.
BungeeCord Diff Regression
Diff Regression config: https://gist.githubusercontent.com/BobSong-dev/26a6c8d6bc2f6b2fbf53b24de39ab7ac/raw/4c2f8ecb6cb1e2a441bf01ce8e5e7f4255fd29a1/bungeecord-indentation.xml
Diff Regression projects: https://gist.githubusercontent.com/BobSong-dev/e0e12b1681c2023dddd7aa6f4336d0a2/raw/67bc1dbaba119c31587bb14bf35da037de74887b/bungeecord-projects.properties
Report label: BungeeCord default Indentation