value keyword for Value Classes
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
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 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.
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
this will likely take a while until it is supported.
valueis 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 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.
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:
- download a nightly build of NetBeans
- use a Valhalla JDK 26 build to run NetBeans (
--jdkhome <path>) - uninstall nb-javac (tools -> plugins -> installed) and restart
(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)