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 da698a8307b..8253ccb9593 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 @@ -51,16 +51,14 @@ public final class TestIdentifier implements Serializable { private static final ObjectStreamField[] serialPersistentFields = ObjectStreamClass.lookup( SerializedForm.class).getFields(); - // Only set during deserialization process - private SerializedForm serializedForm; - - private final UniqueId uniqueId; - private final UniqueId parentId; - private final String displayName; - private final String legacyReportingName; - private final TestSource source; - private final Set tags; - private final Type type; + // These are effectively final but not technically due to late initialization when deserializing + private /* final */ UniqueId uniqueId; + private /* final */ UniqueId parentId; + private /* final */ String displayName; + private /* final */ String legacyReportingName; + private /* final */ TestSource source; + private /* final */ Set tags; + private /* final */ Type type; /** * Factory for creating a new {@link TestIdentifier} from a {@link TestDescriptor}. @@ -78,12 +76,6 @@ public static TestIdentifier from(TestDescriptor testDescriptor) { return new TestIdentifier(uniqueId, displayName, source, tags, type, parentId, legacyReportingName); } - private TestIdentifier(SerializedForm serializedForm) { - this(UniqueId.parse(serializedForm.uniqueId), serializedForm.displayName, serializedForm.source, - serializedForm.tags, serializedForm.type, UniqueId.parse(serializedForm.parentId), - serializedForm.legacyReportingName); - } - private TestIdentifier(UniqueId uniqueId, String displayName, TestSource source, Set tags, Type type, UniqueId parentId, String legacyReportingName) { Preconditions.notNull(type, "TestDescriptor.Type must not be null"); @@ -286,11 +278,14 @@ private void writeObject(ObjectOutputStream s) throws IOException { } private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { - serializedForm = SerializedForm.deserialize(s); - } - - private Object readResolve() { - return new TestIdentifier(serializedForm); + SerializedForm serializedForm = SerializedForm.deserialize(s); + uniqueId = UniqueId.parse(serializedForm.uniqueId); + displayName = serializedForm.displayName; + source = serializedForm.source; + tags = serializedForm.tags; + type = serializedForm.type; + parentId = UniqueId.parse(serializedForm.parentId); + legacyReportingName = serializedForm.legacyReportingName; } /**