diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M2.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M2.adoc index 520bd43a045e..e3579888b611 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M2.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M2.adoc @@ -26,6 +26,7 @@ repository on GitHub. [[release-notes-5.11.0-M2-junit-platform-bug-fixes]] ==== Bug Fixes +* Fixed a bug where `TestIdentifier` could cause a `NullPointerException` on deserialize when there is no parent identifier. See link:https://github.com/junit-team/junit5/issues/3819[issue 3819]. * ❓ [[release-notes-5.11.0-M2-junit-platform-deprecations-and-breaking-changes]] diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java index 4a331d6e50b3..ae3cd416469e 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java @@ -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; } @@ -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; diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java index d971eb7a8e63..7ba6716495e6 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java @@ -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());