Skip to content

Avoid NullPointerException when deserializing TestIdentifier #3837

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[[release-notes-5.10.3]]
== 5.10.3

*Date of Release:*

*Scope:* minor bug fixes and changes since 5.10.2.

For a complete list of all _closed_ issues and pull requests for this release, consult the
link:{junit5-repo}+/milestone/73?closed=1+[5.10.3] milestone page in the JUnit repository
on GitHub.


[[release-notes-5.10.3-junit-platform]]
=== JUnit Platform

==== Bug Fixes

* Fixed a bug where `TestIdentifier` could cause a `NullPointerException` on deserialize when there is no parent identifier.
- See issue link:https://github.com/junit-team/junit5/issues/3819[#3819] for details.


[[release-notes-5.10.3-junit-jupiter]]
=== JUnit Jupiter

No changes.


[[release-notes-5.10.3-junit-vintage]]
=== JUnit Vintage

No changes.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOEx
source = serializedForm.source;
tags = serializedForm.tags;
type = serializedForm.type;
parentId = UniqueId.parse(serializedForm.parentId);
String parentId = serializedForm.parentId;
this.parentId = parentId == null ? null : UniqueId.parse(parentId);
legacyReportingName = serializedForm.legacyReportingName;
}

Expand All @@ -307,7 +308,8 @@ private static class SerializedForm implements Serializable {

SerializedForm(TestIdentifier testIdentifier) {
this.uniqueId = testIdentifier.uniqueId.toString();
this.parentId = testIdentifier.parentId.toString();
UniqueId parentId = testIdentifier.parentId;
this.parentId = parentId == null ? null : parentId.toString();
this.displayName = testIdentifier.displayName;
this.legacyReportingName = testIdentifier.legacyReportingName;
this.source = testIdentifier.source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ void initialVersionCanBeDeserialized() throws Exception {
}
}

@Test
void identifierWithNoParentCanBeSerializedAndDeserialized() throws Exception {
TestIdentifier originalIdentifier = TestIdentifier.from(
new AbstractTestDescriptor(UniqueId.root("example", "id"), "Example") {
@Override
public Type getType() {
return Type.CONTAINER;
}
});

var deserializedIdentifier = (TestIdentifier) deserialize(serialize(originalIdentifier));

assertDeepEquals(originalIdentifier, deserializedIdentifier);
}

private static void assertDeepEquals(TestIdentifier first, TestIdentifier second) {
assertEquals(first, second);
assertEquals(first.getUniqueId(), second.getUniqueId());
Expand Down
Loading