Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Generics/HashCodeTest.java
38828 views
1
/*
2
* Copyright (c) 2004, 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 5097856
27
* @summary Computing hashCode of objects modeling generics shouldn't blow stack
28
* @author Joseph D. Darcy
29
*/
30
31
import java.util.*;
32
import java.lang.reflect.*;
33
34
public class HashCodeTest {
35
36
// Mutually recursive interface types
37
interface Edge<N extends Node<? extends Edge<N>>> {
38
void setEndNode(N n);
39
}
40
interface Node<E extends Edge<? extends Node<E>>> {
41
E getOutEdge();
42
}
43
44
public static void main(String argv[]) {
45
List<Class<?>> classes = new ArrayList<Class<?>>();
46
Set<TypeVariable> typeVariables = new HashSet<TypeVariable>();
47
48
classes.add(java.lang.Class.class);// Simple case
49
classes.add(java.util.Map.class);
50
classes.add(java.lang.Enum.class); // Contains f-bound
51
classes.add(Edge.class);
52
classes.add(Node.class);
53
54
for(Class<?> clazz: classes) {
55
System.out.println(clazz);
56
57
for (TypeVariable<?> tv : clazz.getTypeParameters()) {
58
int hc = tv.hashCode();
59
typeVariables.add(tv);
60
System.out.printf("\t%s 0x%x (%d)%n", tv.getName(), hc, hc);
61
}
62
}
63
64
// Loop over classes again, making sure all type variables are
65
// already present
66
int count = 0;
67
for(Class<?> clazz: classes) {
68
for (TypeVariable<?> tv : clazz.getTypeParameters()) {
69
if (!typeVariables.remove(tv))
70
throw new RuntimeException("Type variable " + tv + " not found.");
71
}
72
}
73
74
if (typeVariables.size() != 0 )
75
throw new RuntimeException("Unexpected number of type variables.");
76
77
}
78
}
79
80