|
16 | 16 | import static org.apiguardian.api.API.Status.STABLE; |
17 | 17 | import static org.junit.platform.commons.util.CollectionUtils.getOnlyElement; |
18 | 18 |
|
19 | | -import java.io.IOException; |
20 | | -import java.io.ObjectInputStream; |
21 | | -import java.io.ObjectOutputStream; |
22 | | -import java.io.ObjectStreamClass; |
23 | | -import java.io.ObjectStreamField; |
24 | 19 | import java.io.Serial; |
25 | 20 | import java.io.Serializable; |
26 | 21 | import java.util.LinkedHashSet; |
|
49 | 44 | public final class TestIdentifier implements Serializable { |
50 | 45 |
|
51 | 46 | @Serial |
52 | | - private static final long serialVersionUID = 1L; |
53 | | - @Serial |
54 | | - @SuppressWarnings("UnusedVariable") |
55 | | - private static final ObjectStreamField[] serialPersistentFields = ObjectStreamClass.lookup( |
56 | | - SerializedForm.class).getFields(); |
| 47 | + private static final long serialVersionUID = 2L; |
| 48 | + |
| 49 | + private final UniqueId uniqueId; |
| 50 | + |
| 51 | + private final @Nullable UniqueId parentId; |
57 | 52 |
|
58 | | - // These are effectively final but not technically due to late initialization when deserializing |
59 | | - private /* final */ UniqueId uniqueId; |
| 53 | + private final String displayName; |
| 54 | + private final String legacyReportingName; |
60 | 55 |
|
61 | | - private /* final */ @Nullable UniqueId parentId; |
| 56 | + private final @Nullable TestSource source; |
62 | 57 |
|
63 | | - private /* final */ String displayName; |
64 | | - private /* final */ String legacyReportingName; |
| 58 | + @SuppressWarnings("serial") // Declared type is Set (not Serializable); actual instances are Serializable. |
| 59 | + private final Set<TestTag> tags; |
65 | 60 |
|
66 | | - private /* final */ @Nullable TestSource source; |
67 | | - private /* final */ Set<TestTag> tags; |
68 | | - private /* final */ Type type; |
| 61 | + private final Type type; |
69 | 62 |
|
70 | 63 | /** |
71 | 64 | * Factory for creating a new {@link TestIdentifier} from a {@link TestDescriptor}. |
@@ -272,87 +265,4 @@ public String toString() { |
272 | 265 | // @formatter:on |
273 | 266 | } |
274 | 267 |
|
275 | | - @Serial |
276 | | - private void writeObject(ObjectOutputStream s) throws IOException { |
277 | | - SerializedForm serializedForm = new SerializedForm(this); |
278 | | - serializedForm.serialize(s); |
279 | | - } |
280 | | - |
281 | | - @Serial |
282 | | - private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { |
283 | | - SerializedForm serializedForm = SerializedForm.deserialize(s); |
284 | | - uniqueId = UniqueId.parse(serializedForm.uniqueId); |
285 | | - displayName = serializedForm.displayName; |
286 | | - source = serializedForm.source; |
287 | | - tags = serializedForm.tags; |
288 | | - type = serializedForm.type; |
289 | | - String parentId = serializedForm.parentId; |
290 | | - this.parentId = parentId == null ? null : UniqueId.parse(parentId); |
291 | | - legacyReportingName = serializedForm.legacyReportingName; |
292 | | - } |
293 | | - |
294 | | - /** |
295 | | - * Represents the serialized output of {@code TestIdentifier}. The fields on this |
296 | | - * class match the fields that {@code TestIdentifier} had prior to 1.8. |
297 | | - */ |
298 | | - private static class SerializedForm implements Serializable { |
299 | | - |
300 | | - @Serial |
301 | | - private static final long serialVersionUID = 1L; |
302 | | - |
303 | | - private final String uniqueId; |
304 | | - |
305 | | - @Nullable |
306 | | - private final String parentId; |
307 | | - |
308 | | - private final String displayName; |
309 | | - private final String legacyReportingName; |
310 | | - |
311 | | - @Nullable |
312 | | - private final TestSource source; |
313 | | - |
314 | | - @SuppressWarnings({ "serial", "RedundantSuppression" }) // always used with serializable implementation (see TestIdentifier#copyOf()) |
315 | | - private final Set<TestTag> tags; |
316 | | - private final Type type; |
317 | | - |
318 | | - SerializedForm(TestIdentifier testIdentifier) { |
319 | | - this.uniqueId = testIdentifier.uniqueId.toString(); |
320 | | - UniqueId parentId = testIdentifier.parentId; |
321 | | - this.parentId = parentId == null ? null : parentId.toString(); |
322 | | - this.displayName = testIdentifier.displayName; |
323 | | - this.legacyReportingName = testIdentifier.legacyReportingName; |
324 | | - this.source = testIdentifier.source; |
325 | | - this.tags = testIdentifier.tags; |
326 | | - this.type = testIdentifier.type; |
327 | | - } |
328 | | - |
329 | | - @SuppressWarnings("unchecked") |
330 | | - private SerializedForm(ObjectInputStream.GetField fields) throws IOException, ClassNotFoundException { |
331 | | - this.uniqueId = (String) fields.get("uniqueId", null); |
332 | | - this.parentId = (String) fields.get("parentId", null); |
333 | | - this.displayName = (String) fields.get("displayName", null); |
334 | | - this.legacyReportingName = (String) fields.get("legacyReportingName", null); |
335 | | - this.source = (TestSource) fields.get("source", null); |
336 | | - this.tags = (Set<TestTag>) fields.get("tags", null); |
337 | | - this.type = (Type) fields.get("type", null); |
338 | | - } |
339 | | - |
340 | | - void serialize(ObjectOutputStream s) throws IOException { |
341 | | - ObjectOutputStream.PutField fields = s.putFields(); |
342 | | - fields.put("uniqueId", uniqueId); |
343 | | - fields.put("parentId", parentId); |
344 | | - fields.put("displayName", displayName); |
345 | | - fields.put("legacyReportingName", legacyReportingName); |
346 | | - fields.put("source", source); |
347 | | - fields.put("tags", tags); |
348 | | - fields.put("type", type); |
349 | | - s.writeFields(); |
350 | | - } |
351 | | - |
352 | | - static SerializedForm deserialize(ObjectInputStream s) throws IOException, ClassNotFoundException { |
353 | | - ObjectInputStream.GetField fields = s.readFields(); |
354 | | - return new SerializedForm(fields); |
355 | | - } |
356 | | - } |
357 | | - |
358 | 268 | } |
0 commit comments