1
1
/*
2
- * Copyright (c) 2017, 2019 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2017, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 8056900
26
+ * @bug 8056900 8338888
27
27
* @summary Verifies message returned with NoClassDefFoundError exception.
28
28
* @library /test/lib
29
29
* @modules java.base/jdk.internal.misc
30
30
* java.compiler
31
- * @run main/native NoClassDefFoundErrorTest
31
+ * @run main/native/othervm -Xlog:exceptions=info NoClassDefFoundErrorTest
32
32
*/
33
33
34
34
import jdk .test .lib .compiler .InMemoryJavaCompiler ;
35
35
import jdk .internal .misc .Unsafe ;
36
36
37
37
public class NoClassDefFoundErrorTest {
38
38
39
+ // Use the specified name
39
40
static native void callDefineClass (String className );
40
41
static native void callFindClass (String className );
42
+ // Use a name longer than a Java string - returns false
43
+ // if native allocation failed.
44
+ static native boolean tryCallDefineClass ();
45
+ static native boolean tryCallFindClass ();
46
+
41
47
static {
42
48
System .loadLibrary ("NoClassDefFoundErrorTest" );
43
49
}
@@ -54,7 +60,7 @@ public static void main(String args[]) throws Exception {
54
60
tooBigClassName = tooBigClassName .append (tooBigClassName );
55
61
}
56
62
57
- // Test JVM_DefineClass() with long name.
63
+ System . out . println ( " Test JVM_DefineClass() with long name" );
58
64
try {
59
65
unsafe .defineClass (tooBigClassName .toString (), klassbuf , 4 , klassbuf .length - 4 , null , null );
60
66
throw new RuntimeException ("defineClass did not throw expected NoClassDefFoundError" );
@@ -64,7 +70,7 @@ public static void main(String args[]) throws Exception {
64
70
}
65
71
}
66
72
67
- // Test JNI_DefineClass() with long name.
73
+ System . out . println ( " Test JNI_DefineClass() with long name" );
68
74
try {
69
75
callDefineClass (tooBigClassName .toString ());
70
76
throw new RuntimeException ("DefineClass did not throw expected NoClassDefFoundError" );
@@ -74,17 +80,17 @@ public static void main(String args[]) throws Exception {
74
80
}
75
81
}
76
82
77
- // Test JNI_FindClass() with long name.
83
+ System . out . println ( " Test JNI_FindClass() with long name" );
78
84
try {
79
85
callFindClass (tooBigClassName .toString ());
80
- throw new RuntimeException ("DefineClass did not throw expected NoClassDefFoundError" );
86
+ throw new RuntimeException ("FindClass did not throw expected NoClassDefFoundError" );
81
87
} catch (NoClassDefFoundError e ) {
82
88
if (!e .getMessage ().contains ("Class name exceeds maximum length of " )) {
83
89
throw new RuntimeException ("Wrong NoClassDefFoundError: " + e .getMessage ());
84
90
}
85
91
}
86
92
87
- // Test JNI_FindClass() with null name.
93
+ System . out . println ( " Test JNI_FindClass() with null name" );
88
94
try {
89
95
callFindClass (null );
90
96
throw new RuntimeException ("FindClass did not throw expected NoClassDefFoundError" );
@@ -93,5 +99,31 @@ public static void main(String args[]) throws Exception {
93
99
throw new RuntimeException ("Wrong NoClassDefFoundError: " + e .getMessage ());
94
100
}
95
101
}
102
+
103
+ System .out .println ("Test JNI_DefineClass() with giant name" );
104
+ try {
105
+ if (tryCallDefineClass ()) {
106
+ throw new RuntimeException ("DefineClass did not throw expected NoClassDefFoundError" );
107
+ } else {
108
+ System .out .println ("Test skipped due to native allocation failure" );
109
+ }
110
+ } catch (NoClassDefFoundError e ) {
111
+ if (!e .getMessage ().contains ("Class name exceeds maximum length of " )) {
112
+ throw new RuntimeException ("Wrong NoClassDefFoundError: " + e .getMessage ());
113
+ }
114
+ }
115
+
116
+ System .out .println ("Test JNI_FindClass() with giant name" );
117
+ try {
118
+ if (tryCallFindClass ()) {
119
+ throw new RuntimeException ("FindClass did not throw expected NoClassDefFoundError" );
120
+ } else {
121
+ System .out .println ("Test skipped due to native allocation failure" );
122
+ }
123
+ } catch (NoClassDefFoundError e ) {
124
+ if (!e .getMessage ().contains ("Class name exceeds maximum length of " )) {
125
+ throw new RuntimeException ("Wrong NoClassDefFoundError: " + e .getMessage ());
126
+ }
127
+ }
96
128
}
97
129
}
0 commit comments