Skip to content

8387484: [lworld] javac should warn on use of value classes#2601

Open
lahodaj wants to merge 2 commits into
openjdk:lworldfrom
lahodaj:javac-depends-on-preview-class
Open

8387484: [lworld] javac should warn on use of value classes#2601
lahodaj wants to merge 2 commits into
openjdk:lworldfrom
lahodaj:javac-depends-on-preview-class

Conversation

@lahodaj

@lahodaj lahodaj commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Consider source files like this:

$ cat /tmp/ValueClass.java 
value class ValueClass {}
$ cat /tmp/TestValue.java 
public class TestValue {
    ValueClass c;
}

When compiled like this:

$ javac --enable-preview --release 28 -Xlint:preview /tmp/ValueClass.java 
/tmp/ValueClass.java:1: warning: [preview] value classes are a preview feature and may be removed in a future release.
value class ValueClass {}
^
1 warning
$ javac --enable-preview --release 28 -Xlint:preview -classpath /tmp /tmp/TestValue.java 
warning: [preview] class file for /tmp/ValueClass.class uses preview features of Java SE 28.
1 warning

Note that while the TestValue.class is marked as preview, there's no warning on the use of ValueClass. This is not aligned with the JEP 12 wording:

When compiling with preview features enabled, any source code reference to (i) a class or interface declared using a preview language feature, ..., causes a preview warning.

Currently javac marks the classfile preview using an explicit test in the ClassWriter, but that does not seem quite right. This PR proposes to mark value classes as Preview.declaredUsingPreviewFeature == true, which should automatically produce a warning, and mark the appropriate classfile as preview.

For the example above:

$ javac --enable-preview --release 28 -Xlint:preview -classpath /tmp /tmp/TestValue.java 
warning: [preview] class file for /tmp/ValueClass.class uses preview features of Java SE 28.
/tmp/TestValue.java:2: warning: [preview] class ValueClass is declared using a preview feature, which may be removed in a future release.
    ValueClass c;
    ^
2 warnings

Note this will also report the warning for Integer, when preview is enabled:

$ cat /tmp/Test.java 
public class Test {
    Integer i;
}
$ javac /tmp/Test.java
$ javac --enable-preview --release 28 -Xlint:preview /tmp/Test.java
warning: [preview] class file for /@/java.base/java/lang/Integer.sig uses preview features of Java SE 28.
/tmp/Test.java:2: warning: [preview] class Integer is declared using a preview feature, which may be removed in a future release.
    Integer i;
    ^
2 warnings


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (1 review required, with at least 1 Committer)

Issue

  • JDK-8387484: [lworld] javac should warn on use of value classes (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/2601/head:pull/2601
$ git checkout pull/2601

Update a local copy of the PR:
$ git checkout pull/2601
$ git pull https://git.openjdk.org/valhalla.git pull/2601/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2601

View PR using the GUI difftool:
$ git pr show -t 2601

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2601.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Jun 30, 2026

Copy link
Copy Markdown

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into lworld will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Jun 30, 2026

Copy link
Copy Markdown

@lahodaj This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8387484: [lworld] javac should warn on use of value classes

Reviewed-by: mcimadamore, liach, vromero

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 7 new commits pushed to the lworld branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@mcimadamore, @liach, @vicente-romero-oracle) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk Bot added the rfr Pull request is ready for review label Jun 30, 2026

@mcimadamore mcimadamore left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice improvement!

*/
public boolean declaredUsingPreviewFeature(Symbol sym) {
return false;
return sym.isValueClass();

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.

Should this include records too given how its semantics are changed? Maybe in another RFE?

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Jun 30, 2026
@mlbridge

mlbridge Bot commented Jun 30, 2026

Copy link
Copy Markdown

Webrevs

@vicente-romero-oracle vicente-romero-oracle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

4 participants