netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

value keyword for Value Classes

Open mambastudio opened this issue 1 month ago • 5 comments

Description

Introduce recognition of the value keyword in Java source files to support Valhalla Early Access builds (OpenJDK 26 and beyond). This enhancement would ensure correct syntax highlighting, parsing, and code completion for the new Value Objects feature introduced under Project Valhalla.

Use case/motivation

The OpenJDK team is standardizing Value Objects as part of Project Valhalla. With the introduction of the value keyword in early-access builds of OpenJDK 26, IDE support is essential for developers testing and adopting this feature. NetBeans should recognize the value keyword similarly to existing Java keywords (e.g., record, sealed, permits) to maintain feature parity and developer experience with other IDEs.

Related issues

No response

Are you willing to submit a pull request?

No

mambastudio avatar Nov 08 '25 19:11 mambastudio

this will likely take a while until it is supported. value is no traditional keyword, it is context sensitive and would get recognized as such using javac after the parsing phase.

Since value objects are no preview feature yet: Even if we would recognize value, the embedded javac would still fail to process the file and show an error at its location. Unless we build a frankenstein nb-javac which is a mix of upstream JDK 26 and the valhalla repo - which might be doable as experimental build but probably not in the release.

mbien avatar Nov 08 '25 19:11 mbien

@mbien that's well understood and it makes sense. It's just that the IDE doesn't allow me to compile the code at all when I try to test it. I had to compromise to a text editor with syntax highlights and use the command prompt. The argument is that it would be nice to have the ability to test certain experimental language features through the IDE.

mambastudio avatar Nov 08 '25 19:11 mambastudio

It's just that the IDE doesn't allow me to compile the code at all

this is a common misconception but NB is not building your project and typically can't prevent your code from being compiled. You may see error badges in the editor and other failures, but only the build system of your project compiles your project (e.g maven).

that being set, I opened https://github.com/apache/netbeans/pull/8995 which produces dev builds which can be used to experiment with valhalla features.

e.g https://github.com/apache/netbeans/actions/runs/19204284796/artifacts/4510676681

mbien avatar Nov 09 '25 16:11 mbien

this will likely take a while until it is supported. value is no traditional keyword, it is context sensitive and would get recognized as such using javac after the parsing phase.

So are record, sealed, permits, var and a few others, namely those that were added added since Java 9. (assert was the last traditional keyword to be added with the release of Java 5, causing backwards compatibility issues for testing frameworks)

ExE-Boss avatar Nov 20 '25 15:11 ExE-Boss

@ExE-Boss yes. But all context sensitive keywords you listed compile fine using nb-javac 25 (the javac build embedded in NB).

nb-javac is intentionally kept unchanged (outside of the fact that it can run on JDK 17) and will be based on javac of JDK 26 next. We don't want to merge valhalla patches into it. Once its a preview feature this won't be a problem but until then value inside a class declaration is a syntax error for nb-javac and it will annotate it as such in the editor.

mbien avatar Nov 20 '25 17:11 mbien

https://github.com/apache/netbeans/pull/9079 implements the value keyword in the semantic layer

We can leave this issue open for informational purposes, but as previously mentioned for it to work the language feature (JEP 401 in this case) would have to make it into the main JDK repo first which the embedded javac is based on.

But to experiment with value objects you can prepare your own NetBeans dev build:

(don't forget to enable preview in your project)

NB will now use the valhalla javac of it's runtime JDK. This should work as long the javac version remains compatible with the NB version. (this also assumes that the valhalla javac doesn't diverge too far from the mainline javac)

mbien avatar Dec 17 '25 02:12 mbien