GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Issue #18614: Fix false positive in IndentationCheck for new operator by mdhamed238 · Pull Request #19684 · checkstyle/checkstyle

Conversation

@mdhamed238

@mdhamed238 mdhamed238 commented Apr 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Issue: #18614

Problem:
IndentationCheck reported false positives for the new operator when tabs were used for indentation.
In NewHandler#getIndentImpl, the old condition compared values from different column systems
(visual/tab expanded vs raw token column), which could mis-detect whether new starts the line.

Fix:
Updated NewHandler#getIndentImpl to use isOnStartOfLine(mainAst), so the check consistently uses tab-expanded visual columns.

Testing:
Added/updated regression coverage in InputIndentationNewWithTabs.java and IndentationCheckTest#testNewWithTabsIndentation, including a try-block case where line-wrapped new is at the start of the line to exercise the fixed path directly. Also reverted unrelated refactoring in testTryBlockConstructorParameters to keep this PR focused.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mdhamed238 mdhamed238 mentioned this pull request Apr 11, 2026
Issue #18614: Fix false positive in IndentationCheck for new operator. #18686
Merged
utafrali
utafrali reviewed Apr 11, 2026
View reviewed changes

@utafrali utafrali left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The one-line fix in NewHandler#getIndentImpl is correct: the old code mixed visual (tab-expanded) and raw column coordinates, which is now fixed by reusing the existing isOnStartOfLine helper. The test file exercises the fixed code path via testCorrectNewLineWrapped, but the testCorrectNewInTryCatch method does not actually test new at the start of a line (where the bug triggers), and an unrelated inline refactoring in testTryBlockConstructorParameters adds unnecessary diff noise. Also, the PR description names the test file as InputIndentationTryBlockNewIssue.java when the actual file added is InputIndentationNewWithTabs.java.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdhamed238 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/NewHandler.java
// if our expression isn't first on the line, just use the start
// of the line
if (getLineStart(mainAst) == mainAst.getColumnNo()) {
if (isOnStartOfLine(mainAst)) {

@utafrali utafrali Apr 11, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The fix is correct. getLineStart(mainAst) returns the visual (tab-expanded) column of the line's first non-whitespace character, while mainAst.getColumnNo() returns the raw token column (each tab counts as 1). With tab indentation these two numbers diverge even when new is at the start of the line, causing the condition to be unexpectedly false and falling into the else branch. Replacing it with isOnStartOfLine(mainAst) (defined as getLineStart(ast) == expandedTabsColumnNo(ast)) makes both sides use the same coordinate system, which is consistent with how checkIndentation() already checks the same token at line 61 of this same class.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdhamed238 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@mdhamed238 mdhamed238 Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread .../puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationNewWithTabs.java

public void testCorrectNewInTryCatch() { //indent:4 exp:4
try { //indent:8 exp:8
client = new Inner( //indent:12 exp:12

@utafrali utafrali Apr 11, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In testCorrectNewInTryCatch, new appears on the same line as client =, so it is NOT at the start of a line. isOnStartOfLine(mainAst) returns false for it, which means the fixed code path in getIndentImpl is never triggered by this method. The regression described in the issue title (false positive for new inside a try block) is not directly covered here. Consider adding a case where new is on its own line inside a try block, e.g.:

		try {
			client =
				new Inner(null);   //indent:16 exp:16
		} catch (Exception e) {
		}

The existing testCorrectNewLineWrapped does exercise the fix, but a try-block-specific case would make the regression more traceable to the original issue.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdhamed238 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

@mdhamed238 mdhamed238 Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good catch, thanks. I updated testCorrectNewInTryCatch so new is now on its own wrapped line inside the try block, which directly exercises the isOnStartOfLine(mainAst) path in getIndentImpl.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
checkConfig.addProperty("tabWidth", "4");

final String fileName = getPath("InputIndentationTryCtorParams.java");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

@utafrali utafrali Apr 11, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The change to testTryBlockConstructorParameters (inlining fileName into the verifyWarns call) is unrelated to the bug fix and adds noise to the diff. It makes it harder to spot that this existing test was not modified for any functional reason. Please revert this change so the diff stays focused on the regression test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdhamed238 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@mdhamed238 mdhamed238 Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Agreed. I reverted that unrelated refactor and restored the original fileName local variable usage so the diff stays focused on the regression fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mdhamed238

mdhamed238 commented Apr 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

The one-line fix in NewHandler#getIndentImpl is correct: the old code mixed visual (tab-expanded) and raw column coordinates, which is now fixed by reusing the existing isOnStartOfLine helper. The test file exercises the fixed code path via testCorrectNewLineWrapped, but the testCorrectNewInTryCatch method does not actually test new at the start of a line (where the bug triggers), and an unrelated inline refactoring in testTryBlockConstructorParameters adds unnecessary diff noise. Also, the PR description names the test file as InputIndentationTryBlockNewIssue.java when the actual file added is InputIndentationNewWithTabs.java.

Thanks! @utafrali Updated the PR description to match the actual test file (InputIndentationNewWithTabs.java) and current fix details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdhamed238
mdhamed238 force-pushed the issue-18614-indentation-new-tabs branch 2 times, most recently from 27608e2 to 81b299f Compare April 11, 2026 17:09
@mdhamed238

mdhamed238 commented Apr 12, 2026

Copy link
Copy Markdown
Contributor Author

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

github-actions[bot] reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

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

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@romani

romani commented Jul 16, 2026

Copy link
Copy Markdown
Member

please let us know if you have no time to finish it now, and somebody else can reuse your code to continue fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@romani romani added the awaiting changes label Jul 16, 2026
@mdhamed238

mdhamed238 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Apologies for the long silence on this PR. After pushing my last changes, all CI checks passed locally, but the report generation step failed, and I was unsure whether the issue was on my side or in the pipeline. I decided to wait for reviewer input before making further changes, and the PR ended up stalling longer than intended.
I now have dedicated time to bring this to completion. I've rebased on the latest master and can address any remaining feedback promptly. Could you let me know if the report generation failure needs action on my end, or if it can be re-triggered? Thank you for your patience.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@romani

romani commented Jul 18, 2026

Copy link
Copy Markdown
Member

rebase you PR on latest, and I will glance as they finish.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdhamed238
mdhamed238 force-pushed the issue-18614-indentation-new-tabs branch from 81b299f to 3b9892e Compare July 18, 2026 02:41
@romani

romani commented Jul 18, 2026

Copy link
Copy Markdown
Member

@mdhamed238 , there is still conflict.

Please read and watch playlist videos at Starting_Development. it explains how to deal with Github ,plase read and watch.

mdhamed238 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdhamed238
mdhamed238 force-pushed the issue-18614-indentation-new-tabs branch 2 times, most recently from 4e04fa1 to 6a473cc Compare July 18, 2026 14:13
@romani

romani commented Jul 18, 2026

Copy link
Copy Markdown
Member

Please rebase one more time, we merged update for Indentation few minutes ago.
Thanks a lot in advance

mdhamed238 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@romani romani removed the awaiting changes label Jul 18, 2026
@mdhamed238
mdhamed238 force-pushed the issue-18614-indentation-new-tabs branch 3 times, most recently from 3d448ea to d7b1fe9 Compare July 19, 2026 00:03
@mdhamed238
Issue checkstyle#18614: Fix false positive in IndentationCheck for ne…
bb0d354
…w operator
@mdhamed238
mdhamed238 force-pushed the issue-18614-indentation-new-tabs branch from d7b1fe9 to bb0d354 Compare July 19, 2026 00:32
romani
romani approved these changes Jul 19, 2026
View reviewed changes

@romani romani left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

issue is fixed by some other update as side effect, thanks a lot for test extension !

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdhamed238 reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@romani
romani merged commit db5a90f into checkstyle:master Jul 19, 2026
130 of 131 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@romani romani mentioned this pull request Jul 19, 2026
False positive: indentation inside of constructor parameters inside try block #18614
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@romani romani romani approved these changes
+1 more reviewer
@utafrali utafrali utafrali left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mdhamed238 @romani @utafrali
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.