Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyDescriptor in PropertyValue needs to be transient to avoid serialization failure [SPR-12377] #16984

Closed
spring-projects-issues opened this issue Oct 25, 2014 · 1 comment
Assignees
Labels
in: core type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 25, 2014

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.

  1. Case 1
    create a PropertyValue Object. then set resolvedDescriptor in the org.springframework.beans package.
    then try to serialize value object.
 
PropertyValue value = new PropertyValue("a", "b");
value.resolvedDescriptor = new PropertyDescriptor("serializable", PropertyValueTests.class);

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)
...

  1. Case 2
    For avoiding serialization failure, make SubPropertyDescriptor which is serializable.
 
PropertyValue value = new PropertyValue("a", "b");
value.resolvedDescriptor = new SubPropertyDescriptor("serializable", PropertyValueTests.class);
SubPropertyDescriptor.java

	public class SubPropertyDescriptor extends PropertyDescriptor implements Serializable {

		public SubPropertyDescriptor(String propertyName, Class<?> beanClass)
				throws IntrospectionException {
			super(propertyName, beanClass);
		}

		public SubPropertyDescriptor() throws IntrospectionException {
			// There is no-args constructor in the PropertyDescriptor.
			super("serializable", PropertyValueTests.class);
		}

	}

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

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 25, 2014

jongmin moon commented

I hava submitted a pull-request in the #676.
Thank you.

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.1.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants