-
Notifications
You must be signed in to change notification settings - Fork 911
Open
Labels
Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fixBug report or fix
Description
Apache NetBeans version
Apache NetBeans 27
What happened
A record class that is package-private is always shown as unused, unless there is a constructor invocation ("new" expression) in the same source file. The record class name is syntax-highlighted as unused, and a hint 'Remove unused "{record name}"' is shown, although the class is used within the same package.
Language / Project Type / NetBeans Component
No response
How to reproduce
Create a package-private record class:
package net.example;
record Example(int n) { }
Add a use of it in the same package:
package net.example;
class Test { { System.out.println(new Example(0).n()); } }
=> The declaration of record Example erroneously shows it as unused.
Add a usage within the same source file as the record class:
package net.example;
record Example(int n) { }
class Test2 { { new Example(0); } }
=> The "unused" disappears.
Replace the record class by a regular class:
package net.example;
class Example { int n; Example(int n) { } int n() { return n; } }
=> The "unused" disappears as well.
Did this work correctly in an earlier version?
No / Don't know
Operating System
Windows 10
JDK
21
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
No response
Are you willing to submit a pull request?
No
Metadata
Metadata
Assignees
Labels
Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fixBug report or fix