On Wed, 1 Jul 2026 23:26:50 GMT, Chen Liang <[email protected]> wrote:
> Make sure object-writing serialization fails for "strict in serializable > super". We currently already fail when they are deserialized. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). I don't have familiarity with this code, but having looked at it the last few days, this change looks reasonable to me. I haven't had a chance to run my own experiments, but does this change address any issue that might have arisen if the strictly initialized instance field belonged to some parent (identity) class that was not an immediate parent of the object instance being serialized/deserialized? For example, the following class hierarchy: class IdentityGrandParent implements Serializable { // strictly initialized instance field int x; } class IdentityParent extends IdentityGrandParent { // no instance fields } class Identity extends IdentityParent { // no instance fields } and then serialize/deserialize and instance of `Identity` class: ObjectOutputStream.writeObject(new Identity()); Perhaps the `ValueSerializationTest` can be enhanced to include this case? test/jdk/java/io/Serializable/valueObjects/ValueSerializationTest.java line 270: > 268: @ParameterizedTest > 269: @MethodSource("classes") > 270: void testDeser(Class<?> valueClass, byte flags, Class<? extends > Exception> expectedException) Now that the incoming `Class` is not always a value class, I think we should rename this parameter to just `cls` or something else. At the same time, the comment on the test method would need an update too, maybe: > A byte stream is generated containing a reference to the given class ... ------------- PR Comment: https://git.openjdk.org/valhalla/pull/2612#issuecomment-4865958652 PR Review Comment: https://git.openjdk.org/valhalla/pull/2612#discussion_r3513210594
