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

MimeType is no longer actually serializable #26127

Closed
holmis83 opened this issue Nov 20, 2020 · 2 comments
Closed

MimeType is no longer actually serializable #26127

holmis83 opened this issue Nov 20, 2020 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Milestone

Comments

@holmis83
Copy link

Affects: 5.2.10 and up

The org.springframework.util.MimeType class implements Serializable interface, but since the resolvedCharset field was introduced in 5.2.10, serialization with charset will fail since Charset class does not implement Serializable.

Code to reproduce:

MimeType mimeType = new MimeType("text", "plain", StandardCharsets.UTF_8);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(mimeType);

On OpenJDK 8 & 11 (Ubuntu), the above gives java.io.NotSerializableException.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 20, 2020
@sbrannen
Copy link
Member

Thanks for raising the issue.

I have confirmed this by adding the following test to MimeTypeTests.

@Test
void isSerializable() throws Exception {
	MimeType mimeType = new MimeType("text", "plain", StandardCharsets.UTF_8);
	SerializationTestUtils.testSerialization(mimeType);
}

That test fails on master with:

java.io.NotSerializableException: sun.nio.cs.UTF_8
	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)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.springframework.core.testfixture.io.SerializationTestUtils.testSerialization(SerializationTestUtils.java:40)
	at org.springframework.util.MimeTypeTests.isSerializable(MimeTypeTests.java:49)

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 20, 2020
@sbrannen sbrannen added this to the 5.2.12 milestone Nov 20, 2020
@sbrannen
Copy link
Member

Regression caused by #25808.

@jhoeller jhoeller self-assigned this Nov 20, 2020
@jhoeller jhoeller modified the milestones: 5.2.12, 5.3.2 Nov 20, 2020
@jhoeller jhoeller added the for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x label Nov 20, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x labels Nov 20, 2020
@jhoeller jhoeller changed the title MimeType is no longer Serializable MimeType is no longer actually serializable Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants