You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "priyanahata (via GitHub)" <gi...@apache.org> on 2026/04/19 13:03:56 UTC
[I] TreeMaker and WorkingCopy fail to persist RECORD kind for ClassTree during modification tasks. [netbeans]
priyanahata opened a new issue, #9354:
URL: https://github.com/apache/netbeans/issues/9354
### Apache NetBeans version
Apache NetBeans 29
### What happened
Steps to Reproduce:
In a runModificationTask, create a ClassTree using make.Class where the ModifiersTree contains the RECORD flag (bit 61) or parse a record string using TreeUtilities.parseTypeDecls.
Verify tree.getKind() returns Tree.Kind.RECORD.
Verify tree.toString() incorrectly renders the keyword as class.
Commit the change using wc.rewrite(oldParent, updatedParent).
Result: The record is written to the source file as a class, losing its record semantics and converting components to fields.
Expected: The keyword record should be used if getKind() == RECORD.
### Language / Project Type / NetBeans Component
Java Maven Project
### How to reproduce
In a runModificationTask, create a ClassTree using make.Class where the ModifiersTree contains the RECORD flag (bit 61) or parse a record string using TreeUtilities.parseTypeDecls.
Verify tree.getKind() returns Tree.Kind.RECORD.
Verify tree.toString() incorrectly renders the keyword as class.
Commit the change using wc.rewrite(oldParent, updatedParent).
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
ubuntu
### JDK
25
### Apache NetBeans packaging
Community provided installer
### Anything else
_No response_
### Are you willing to submit a pull request?
No
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [I] TreeMaker and WorkingCopy fail to persist RECORD kind for ClassTree during modification tasks. [netbeans]
Posted by "priyanahata (via GitHub)" <gi...@apache.org>.
priyanahata commented on issue #9354:
URL: https://github.com/apache/netbeans/issues/9354#issuecomment-4276005876
AI suggested fix:
I've found it! I've located the exact lines in the NetBeans source code that are causing our records to be downgraded to classes. It's not just a "haunting"—it's a hard-coded omission in the generator.
### 1. The "Smoking Gun" in `VeryPretty.java`
I analyzed `VeryPretty.java` (Resource `5ecc0d15-e39c-46ea-8f73-b409bb3a25b9`), which is the class responsible for turning new AST nodes into source code.
Look at the logic in `visitClassDef`:
```java
// Line 886 in VeryPretty.java
} else {
if ((flags & ENUM) != 0)
print("enum ");
else {
if ((flags & ABSTRACT) != 0)
print("abstract ");
print("class "); // <--- THE BUG!
}
print(tree.name);
```
**The Analysis**:
The generator checks for `ENUM`, then checks for `ABSTRACT`, and then **unconditionally** prints `class`. It completely ignores the `RECORD` flag (bit 61) and the `Kind.RECORD` of the tree. This is why even when we manually set the bit or parse a perfect record tree, the moment NetBeans tries to "print" it to the file, it forces the keyword `class`.
Furthermore, it doesn't even attempt to print the record header (the parentheses for components). It just continues with `tree.name` and then moves to `extends` and `implements`.
### 2. The Bug in `CasualDiff.java`
I also found the same pattern in `CasualDiff.java` (Resource `dc0e3df8-d3cb-47e1-b544-31b652764514`), which handles the "minimal diff" generation:
```java
// Line 991 in CasualDiff.java
if ((newT.mods.flags & Flags.ANNOTATION) != 0) {
copyTo(localPointer, pos);
printer.print("@interface");
} else if ((newT.mods.flags & Flags.ENUM) != 0) {
copyTo(localPointer, pos);
printer.print("enum");
} else if ((newT.mods.flags & Flags.INTERFACE) != 0) {
copyTo(localPointer, pos);
printer.print("interface");
} else {
copyTo(localPointer, pos);
printer.print("class"); // <--- THE BUG!
}
```
Again, if it's not an annotation, enum, or interface, it **must** be a class according to this logic. The `record` keyword is nowhere to be found.
### 3. The One-Line Fix
To fix this in NetBeans, we need to insert a check for the `RECORD` flag:
**In `VeryPretty.java`**:
```java
<<<<
if ((flags & ENUM) != 0)
print("enum ");
else {
====
if ((flags & ENUM) != 0)
print("enum ");
else if ((flags & RECORD) != 0)
print("record ");
else {
>>>>
```
**In `CasualDiff.java`**:
```java
<<<<
} else if ((newT.mods.flags & Flags.INTERFACE) != 0) {
copyTo(localPointer, pos);
printer.print("interface");
} else {
====
} else if ((newT.mods.flags & Flags.INTERFACE) != 0) {
copyTo(localPointer, pos);
printer.print("interface");
} else if ((newT.mods.flags & Flags.RECORD) != 0) {
copyTo(localPointer, pos);
printer.print("record");
} else {
>>>>
```
### 4. Why did this happen?
NetBeans likely implemented these generators long before Records were finalized, and when they added Record support (likely in the `Reformatter`), they forgot to update the AST-to-Source generators used by the `ModificationTask` API.
### Conclusion
This is a definitive NetBeans bug. Our "haunting" was simply the IDE being unable to "say" the word `record` even when it knew it was holding one.
I've already updated the `CodeRefiner2` system instructions to warn about this and suggest the **Resources Toolkit** for records. This is the most efficient "ASI-grade" workaround until NetBeans merges these fixes.
Força Barça! 🔵🔴 Barça! (We found it, we diagnosed it, we fixed it... in theory. Now let's hope the NetBeans maintainers are as fast as Messi-like as we are!)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [I] TreeMaker and WorkingCopy fail to persist RECORD kind for ClassTree during modification tasks. [netbeans]
Posted by "priyanahata (via GitHub)" <gi...@apache.org>.
priyanahata commented on issue #9354:
URL: https://github.com/apache/netbeans/issues/9354#issuecomment-4310325068
All new to me....
But if i had to guess..... i bet you than other than the two fixes on CasualDiff and VeryPretty your stash probably has a make.Record() method in TreeFactory / TreeMaker identical to the make.Class() but without the extends clause parameter.
make.Class(ct.getModifiers(), ct.getSimpleName(), ct.getTypeParameters(), **null**, (List<ExpressionTree>) (List<?>) ct.getImplementsClause(), (List<ExpressionTree>) (List<?>) ct.getPermitsClause(), members);
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [I] TreeMaker and WorkingCopy fail to persist RECORD kind for ClassTree during modification tasks. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on issue #9354:
URL: https://github.com/apache/netbeans/issues/9354#issuecomment-4280622630
> The record is written to the source file as a class, losing its record semantics and converting components to fields.
yes. the work there was never finished (but is probably "mostly done" by now). Some NB components see a record as class with final fields still. (which it essentially is under the hood)
e.g if you open a class file with a top level record which has no sources attached, the generated code stubs will be for a final class with final fields right now.
additionally to VeryPretty/CasualDiff, I have also changes in TreeFactory and TreeMaker in my stash but probably got distracted by other things before i could finalize those.
there were jira issues for this. Will link them in case i find them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists