eclipse-jdt / eclipse-jdt/eclipse.jdt.core

[BETA_JAVA28] ECJ should consider emitting warning for value classes that will fail serialization at run time.

Open
#5,331 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

https://openjdk.org/jeps/401 reads:

`Serialization of value records works automatically, but serialization of non-record value classes requires manual intervention. Value classes that implement Serializable must implement the [writeReplace](https://download.java.net/java/early_access/jdk28/docs/specs/serialization/output.html#the-writereplace-method) and [readResolve](https://download.java.net/java/early_access/jdk28/docs/specs/serialization/input.html#the-readresolve-method) methods so that a replacement object is serialized and deserialized in place of the value object itself. If these methods are not implemented, attempts to serialize or deserialize the value object will fail with an InvalidClassException.

These methods must be implemented because value classes are compiled using [strictly-initialized fields](https://openjdk.org/jeps/539), and deserialization cannot safely initialize such fields. Value objects may only be created, and their fields initialized, by invoking a constructor. In the future, we expect to enhance the serialization mechanism so that serializable value classes can be serialized and deserialized automatically.

javac issues serial warnings for value classes that will fail serialization at run time.`

ECJ should consider emitting similar warnings - see that this is outside the purview of JLS. As in compilers are _not_ mandated to emit these warnings. The draft JLS specification is silent about these warnings - see https://download.java.net/java/early_access/jdk28/docs/specs/value-objects-jls.html

Contributor guide

Open the contributing guide

Research direction

Start by reviewing ECJ's existing handling of serial warnings and the JEP 401 and value-objects JLS links in the issue. Locate the compiler entry point and tests for value classes and serialization diagnostics; done means ECJ emits a comparable warning for value classes that implement Serializable without the required replacement methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.