Path: blob/master/test/jdk/java/rmi/MarshalledObject/compare/Compare.java
41152 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 409631226* @summary Codebase annotations on classes that are marshalled should not27* affect the behavior of MarshalledObject.equals. Only the bytes28* not involved in location should be compared.29* @author Ken Arnold30*31* @run main/othervm Compare 11 annotatedRef32*/3334import java.rmi.MarshalledObject;35import java.io.*;3637public class Compare {38static class Node implements Serializable {39int value = nextValue++;40Node next;4142static int nextValue = 1;43};4445private static MarshalledObject made;46private static MarshalledObject read;4748public static void main(String[] args) throws Throwable {49if (args.length == 1)50writeObjToOut(Integer.parseInt(args[0]));51else52compareObjToFile(args[0], args[1]);53}5455static void writeObjToOut(int listLength) throws Throwable {56ObjectOutputStream out = new ObjectOutputStream(System.out);57out.writeObject(marshalledList(listLength));58out.close();59}6061public static void compareHashCodes(String[] args) throws Throwable {62File f = new File(System.getProperty("test.src", "."), args[1]);63setupObjects(args[0], f);64if (made.hashCode() != read.hashCode()) {65throw new RuntimeException(66"made.hashCode(){" + made.hashCode() + "} != " +67"read.hashCode(){" + read.hashCode() + "}"68);69}70}7172static void compareObjToFile(String lengthStr, String file0) throws Throwable73{74File f = new File(System.getProperty("test.src", "."), file0);75setupObjects(lengthStr, f);76if (!made.equals(read) || !read.equals(made)) {77throw new RuntimeException(78"made.equals(read) = " + made.equals(read)79+ ", read.equals(made) = " + read.equals(made)80);81}82}8384static MarshalledObject setupObjects(String lengthStr, File file)85throws Throwable86{87int listLength = Integer.parseInt(lengthStr);88made = marshalledList(listLength);89ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));90read = (MarshalledObject) in.readObject();91in.close();92return read;93}9495static MarshalledObject marshalledList(int length) throws Throwable {96Node head = null;97Node cur = null;98for (int i = 0; i < length; i++) {99if (head == null)100cur = head = new Node();101else102cur = cur.next = new Node();103}104System.err.println("head = " + head);105return new MarshalledObject(head);106}107}108109110