Skip to content

Issue #17036: Variable os is never used#17039

Closed
Pankraz76 wants to merge 1 commit intocheckstyle:masterfrom
Pankraz76:fix-LocalVariableNameCheck
Closed

Issue #17036: Variable os is never used#17039
Pankraz76 wants to merge 1 commit intocheckstyle:masterfrom
Pankraz76:fix-LocalVariableNameCheck

Conversation

@Pankraz76
Copy link
Copy Markdown

@Pankraz76 Pankraz76 commented May 8, 2025

Issue #17036: Variable os is never used

pos: test:
image

neg: test:
image

@Pankraz76 Pankraz76 force-pushed the fix-LocalVariableNameCheck branch from 3d55b9a to 6be15aa Compare May 8, 2025 13:10
Copy link
Copy Markdown
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

public void write() throws IOException {
try (OutputStream os = Files.newOutputStream(null)) { // violation, unused variable 'os'
return;
}
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.

Check is right,
Maybe be input test code should be a bit more realistic to let us understand a problem.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes of course but its 1o1 from real world. We have test and failing production so we can fix it. Thx.

Copy link
Copy Markdown
Member

@romani romani May 8, 2025

Choose a reason for hiding this comment

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

What happens in real code if we remove unused?
I still don't see problem

@Pankraz76 Pankraz76 force-pushed the fix-LocalVariableNameCheck branch from 6be15aa to c1ce6f9 Compare May 10, 2025 09:30
Copy link
Copy Markdown
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:

Comment on lines +20 to +26
try {
OutputStream os = Files.newOutputStream(null); // violation, unused variable 'os'
} catch (IOException e) {
throw new RuntimeException(e);
}
try (OutputStream os = Files.newOutputStream(null)) { // violation, unused variable 'os'
System.out.println("os");
Copy link
Copy Markdown
Member

@romani romani May 10, 2025

Choose a reason for hiding this comment

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

[ERROR] Failures: 
[ERROR]   UnusedLocalVariableCheckTest.testIssue17036:589->AbstractModuleTestSupport.verifyWithInlineConfigParser:260->AbstractModuleTestSupport.verifyViolations:614 Violation lines for /home/vsts/work/1/s/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unusedlocalvariable/InputUnusedLocalVariableIssue17036.java differ.
missing (1): 25
---
expected   : [21, 25]
but was    : [21]

do you mean that we missing to report violation on line 25 ? sounds like valid defect in Check , false-negative.
please prove that it missing violation by CLI, to make sure there is no other side effect affects execution

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes have to check what you mean with CLI. the message output message is not important right?
This here is easy starter to overtake and fix.

If i cant provide maybe someone else can supplement.

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.

CLI https://checkstyle.sourceforge.io/cmdline.html

if you run it as shown at https://github.com/checkstyle/checkstyle/blob/master/.github/ISSUE_TEMPLATE/bug_report.md you will share all that is requried to avoid any extra conversations

@Pankraz76
Copy link
Copy Markdown
Author

reopen if POI

@Pankraz76 Pankraz76 closed this May 14, 2025
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.

2 participants