diff --git a/src/share/classes/java/io/ObjectStreamClass.java b/src/share/classes/java/io/ObjectStreamClass.java index 41b116d41bcbeed003ba724443e79a7ba01d467c..71f278e1b94732e398af9525c45ac2eb1bf1eaea 100644 --- a/src/share/classes/java/io/ObjectStreamClass.java +++ b/src/share/classes/java/io/ObjectStreamClass.java @@ -1151,7 +1151,14 @@ public class ObjectStreamClass implements Serializable { end = end.getSuperclass(); } + HashSet oscNames = new HashSet<>(3); + for (ObjectStreamClass d = this; d != null; d = d.superDesc) { + if (oscNames.contains(d.name)) { + throw new InvalidClassException("Circular reference."); + } else { + oscNames.add(d.name); + } // search up inheritance hierarchy for class with matching name String searchName = (d.cl != null) ? d.cl.getName() : d.name;