8378908: [lworld] Serializations warnings for value classes that have private serialization methods#2187
Conversation
… private serialization methods
| case "readObject" -> checkReadObject(tree,e, method); | ||
| case "readObjectNoData" -> checkReadObjectNoData(tree, e, method); | ||
| case "readResolve" -> checkReadResolve(tree, e, method); | ||
| case "writeObject" -> isSerialMethodCorrect[0] = hasAppropriateWriteObject(tree, e, method); |
There was a problem hiding this comment.
some changes in this method and in the methods invoked here were not strictly necessary but were done for the sake of uniformity
There was a problem hiding this comment.
Can we convert this to a switch expression, like:
isSerialMethodCorrect[0] = switch (name) {
case "writeObject" -> hasAppropriateWriteObject(tree, e, method);and so on.
|
👋 Welcome back vromero! A progress list of the required criteria for merging this PR into |
|
@vicente-romero-oracle 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: 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 no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
| case "readObject" -> checkReadObject(tree,e, method); | ||
| case "readObjectNoData" -> checkReadObjectNoData(tree, e, method); | ||
| case "readResolve" -> checkReadResolve(tree, e, method); | ||
| case "writeObject" -> isSerialMethodCorrect[0] = hasAppropriateWriteObject(tree, e, method); |
There was a problem hiding this comment.
Can we convert this to a switch expression, like:
isSerialMethodCorrect[0] = switch (name) {
case "writeObject" -> hasAppropriateWriteObject(tree, e, method);and so on.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Outdated
Show resolved
Hide resolved
…java Co-authored-by: Chen Liang <liach@openjdk.org>
…java Co-authored-by: Chen Liang <liach@openjdk.org>
| * @throws InvalidObjectException always | ||
| */ | ||
| @java.io.Serial | ||
| @SuppressWarnings("serial") |
There was a problem hiding this comment.
The other uses of @SuppressSerial in the JDK tend to have a comment explaining why the warning is being suppressed.
| // fields | ||
| final boolean[] hasWriteReplace = {false}; | ||
| final Map<String, Symbol> declaredSerialMethodNames = new HashMap<>(); | ||
| final boolean[] isSerialMethodCorrect = new boolean[] { false }; |
There was a problem hiding this comment.
Why is a one-element boolean array being used as opposed to a (non-final) boolean?
There was a problem hiding this comment.
Because this is passed to a lambda expression, which requires final local variables.
There was a problem hiding this comment.
This variable is no longer used outside of runUnderLint, we can convert it to a local at the switch where it is assigned.
| LintWarnings.SerializableValueClassWithoutWriteReplace2); | ||
| } | ||
| } | ||
| if (c.isValueClass()) { |
There was a problem hiding this comment.
I think a short comment here explaining the rules for serializable value classes would be helpful.
|
|
||
| // Check for missing serialVersionUID; check *not* done | ||
| // for enums or records. | ||
| VarSymbol svuidSym = null; |
There was a problem hiding this comment.
Do value classes need any distinct serialVersionUID handling?
There was a problem hiding this comment.
not sure I get your question. Why should they?
There was a problem hiding this comment.
Hi @RogerRiggs, thanks for making a comment in an OpenJDK project!
All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user RogerRiggs" for the summary.
If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.
- I agree to the OpenJDK Terms of Use for all comments I make in a project in the OpenJDK GitHub organization.
Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.
There was a problem hiding this comment.
not sure I get your question. Why should they?
I don't know if they do; that's why I was asking :-)
I think my concerns would be addressed by a "here's how serial value classes work."
There was a problem hiding this comment.
Oh I see, thanks @RogerRiggs for your answer. I didn't know that specific about migrated value classes. I will add a comment
There was a problem hiding this comment.
Hi @RogerRiggs, thanks for making a comment in an OpenJDK project!
All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user RogerRiggs" for the summary.
If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.
- I agree to the OpenJDK Terms of Use for all comments I make in a project in the OpenJDK GitHub organization.
Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.
There was a problem hiding this comment.
Do value classes need any distinct serialVersionUID handling?
Value classes have the same requirements (non-requirements) as identity classes.
They are used to confirm the match between the class and the serialized stream contents.
Migrated value classes especially need the value class and identity class to have the same SVUID.
There was a problem hiding this comment.
Oh I see, thanks @RogerRiggs for your answer. I didn't know that specific about migrated value classes. I will add a comment
Formally, use of the proxy pattern is recommended for value classes. Where-in, the writeReplace method is invoked to provide the proxy object to be serialized. A record is recommended since it has a stable nominative serialized form. When the proxy object is deserialized, its readReplace is invoked to construct the object.
The Valhalla ObjectOutputStream and ObjectInputStream describe the process. (Maybe more words are needed).
For migrated java.base classes there is a private protocol implemented in ObjectInputStream to use a constructor of each class to create the value objects from the field values extracted from the serialized form.
The spec in this area is weak and vague, since it is not intended for general use. More work is needed in this area of the spec.
|
@vicente-romero-oracle, updates generally looks good; I can given a final re-review after JavaOne. |
| // fields | ||
| final boolean[] hasWriteReplace = {false}; | ||
| final Map<String, Symbol> declaredSerialMethodNames = new HashMap<>(); | ||
| final boolean[] isSerialMethodCorrect = new boolean[] { false }; |
There was a problem hiding this comment.
This variable is no longer used outside of runUnderLint, we can convert it to a local at the switch where it is assigned.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Chen Liang <liach@openjdk.org>
Co-authored-by: Chen Liang <liach@openjdk.org>
Co-authored-by: Chen Liang <liach@openjdk.org>
|
|
| * @throws InvalidObjectException always | ||
| */ | ||
| @java.io.Serial | ||
| @SuppressWarnings("serial") // this method is not invoked for value classes |
There was a problem hiding this comment.
Perhaps as future work, it would be technically possible for the serial lint checks to look inside the body of a method like this, notice the method always throws an exception, and elide the warning in that case. (It is a little unfortunate to "penalize" the java.time method for being robust in their serial handing by requiring new suppress warnings.)
Various known enhancements to the serial checking envision that deep inspection of lint checking, as in JDK-7019074.
There was a problem hiding this comment.
thanks @jddarcy, I have created: https://bugs.openjdk.org/browse/JDK-8381637 to address this issue. Are you OK with the PR?
There was a problem hiding this comment.
Hmm, would it be easy for Javac to determine a method alwys finishes exceptionally?
This PR is adding a new serialization warning for the case when a value class declares one of the following serialization related methods:
They have no effect if declared in value classes, fact that should be notified to the user,
TIA
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/2187/head:pull/2187$ git checkout pull/2187Update a local copy of the PR:
$ git checkout pull/2187$ git pull https://git.openjdk.org/valhalla.git pull/2187/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 2187View PR using the GUI difftool:
$ git pr show -t 2187Using diff file
Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2187.diff
Using Webrev
Link to Webrev Comment