PropertyDescriptor in PropertyValue needs to be transient to avoid serialization failure [SPR-12377] #16984
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
jongmin moon opened SPR-12377 and commented
org.springframework.beans.PropertyValue is Serializable and has a member PropertyDescriptor.
Even though threre is little possible to have a Exception when serialization and deSerialization
because the access modifier of PropertyDescriptor is defualt,
PropertyDescriptor needs to be transient.
create a PropertyValue Object. then set resolvedDescriptor in the org.springframework.beans package.
then try to serialize value object.
in this case PropertyDescriptor is not a Serializable class, when writeObject(value) is called,
Exception occurs like below as you know.
java.io.NotSerializableException: java.beans.PropertyDescriptor
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
...
For avoiding serialization failure, make SubPropertyDescriptor which is serializable.
in this case SubPropertyDescriptor is a Serializable class, so serialization is successful.
But when ObjectInputStream.readObject is called for deSerialization,
Exception occurs like below as you know because the parent class PropertyDescriptor does not have
no-args default constructor.
java.io.InvalidClassException: org.springframework.beans.PropertyValueTests$SubPropertyDescriptor; no valid constructor
at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150)
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:768)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
...
So, I think the filed PropertyDescriptor in the org.springframework.beans.PropertyValue needs to be transient.
I attach a my test code file.
Affects: 4.1.1
Attachments:
Referenced from: commits a13bb69
The text was updated successfully, but these errors were encountered: