Skip to content

Commit

Permalink
Platform: Avoid SerializedForm reference
Browse files Browse the repository at this point in the history
Prior to this commit each `TestIdentifier` instance required memory for
storing a `null` reference.
  • Loading branch information
marcphilipp committed Jan 8, 2021
1 parent cfc73e5 commit b1558b9
Showing 1 changed file with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestTag> 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<TestTag> tags;
private /* final */ Type type;

/**
* Factory for creating a new {@link TestIdentifier} from a {@link TestDescriptor}.
Expand All @@ -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<TestTag> tags, Type type,
UniqueId parentId, String legacyReportingName) {
Preconditions.notNull(type, "TestDescriptor.Type must not be null");
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit b1558b9

Please sign in to comment.