test/jdk/java/io/Serializable/verifyDynamicObjHandleTable/VerifyDynamicObjHandleTable.java
changeset 58565 baa5969ecf34
parent 47216 71c04702a3d5
equal deleted inserted replaced
58564:218a1a642c6f 58565:baa5969ecf34
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    29 import java.io.*;
    29 import java.io.*;
    30 import java.util.HashSet;
    30 import java.util.HashSet;
    31 import java.util.Iterator;
    31 import java.util.Iterator;
    32 
    32 
    33 class A implements Serializable {
    33 class A implements Serializable {
    34     static HashSet writeObjectExtent = new HashSet();
    34     private static final long serialVersionUID = 1L;
       
    35 
       
    36     static HashSet<A> writeObjectExtent = new HashSet<>();
    35 
    37 
    36     private void writeObject(ObjectOutputStream out) throws IOException {
    38     private void writeObject(ObjectOutputStream out) throws IOException {
    37         if (writeObjectExtent.contains(this)) {
    39         if (writeObjectExtent.contains(this)) {
    38             throw new InvalidObjectException("writeObject: object " +
    40             throw new InvalidObjectException("writeObject: object " +
    39                                              this.toString() + " has already "
    41                                              this.toString() + " has already "
    61 
    63 
    62         // Make sure that serialization subsystem does not
    64         // Make sure that serialization subsystem does not
    63         // allow writeObject to be called on any objects that
    65         // allow writeObject to be called on any objects that
    64         // have already been serialized. These objects should be
    66         // have already been serialized. These objects should be
    65         // written out by reference.
    67         // written out by reference.
    66         Iterator iter = A.writeObjectExtent.iterator();
    68         Iterator<A> iter = A.writeObjectExtent.iterator();
    67         while (iter.hasNext()) {
    69         while (iter.hasNext()) {
    68             out.writeObject(iter.next());
    70             out.writeObject(iter.next());
    69         }
    71         }
    70 
    72 
    71         out.close();
    73         out.close();