Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/MarshalledObject/compare/Compare.java
41152 views
1
/*
2
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 4096312
27
* @summary Codebase annotations on classes that are marshalled should not
28
* affect the behavior of MarshalledObject.equals. Only the bytes
29
* not involved in location should be compared.
30
* @author Ken Arnold
31
*
32
* @run main/othervm Compare 11 annotatedRef
33
*/
34
35
import java.rmi.MarshalledObject;
36
import java.io.*;
37
38
public class Compare {
39
static class Node implements Serializable {
40
int value = nextValue++;
41
Node next;
42
43
static int nextValue = 1;
44
};
45
46
private static MarshalledObject made;
47
private static MarshalledObject read;
48
49
public static void main(String[] args) throws Throwable {
50
if (args.length == 1)
51
writeObjToOut(Integer.parseInt(args[0]));
52
else
53
compareObjToFile(args[0], args[1]);
54
}
55
56
static void writeObjToOut(int listLength) throws Throwable {
57
ObjectOutputStream out = new ObjectOutputStream(System.out);
58
out.writeObject(marshalledList(listLength));
59
out.close();
60
}
61
62
public static void compareHashCodes(String[] args) throws Throwable {
63
File f = new File(System.getProperty("test.src", "."), args[1]);
64
setupObjects(args[0], f);
65
if (made.hashCode() != read.hashCode()) {
66
throw new RuntimeException(
67
"made.hashCode(){" + made.hashCode() + "} != " +
68
"read.hashCode(){" + read.hashCode() + "}"
69
);
70
}
71
}
72
73
static void compareObjToFile(String lengthStr, String file0) throws Throwable
74
{
75
File f = new File(System.getProperty("test.src", "."), file0);
76
setupObjects(lengthStr, f);
77
if (!made.equals(read) || !read.equals(made)) {
78
throw new RuntimeException(
79
"made.equals(read) = " + made.equals(read)
80
+ ", read.equals(made) = " + read.equals(made)
81
);
82
}
83
}
84
85
static MarshalledObject setupObjects(String lengthStr, File file)
86
throws Throwable
87
{
88
int listLength = Integer.parseInt(lengthStr);
89
made = marshalledList(listLength);
90
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
91
read = (MarshalledObject) in.readObject();
92
in.close();
93
return read;
94
}
95
96
static MarshalledObject marshalledList(int length) throws Throwable {
97
Node head = null;
98
Node cur = null;
99
for (int i = 0; i < length; i++) {
100
if (head == null)
101
cur = head = new Node();
102
else
103
cur = cur.next = new Node();
104
}
105
System.err.println("head = " + head);
106
return new MarshalledObject(head);
107
}
108
}
109
110