Skip to content

Commit 6296463

Browse files
committed
svm: adopt "JDK-8348986: Improve coverage of enhanced exception messages"
1 parent 261174a commit 6296463

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess;
3939
import org.graalvm.nativeimage.hosted.Feature.FeatureAccess;
4040
import org.graalvm.nativeimage.hosted.RuntimeJNIAccess;
41+
import org.graalvm.nativeimage.hosted.RuntimeReflection;
4142
import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport;
4243

4344
import com.oracle.svm.core.util.ConcurrentIdentityHashMap;
@@ -109,6 +110,9 @@ protected static void registerForThrowNew(FeatureAccess access, String... except
109110
for (String exceptionClassName : exceptionClassNames) {
110111
RuntimeJNIAccess.register(clazz(access, exceptionClassName));
111112
RuntimeJNIAccess.register(constructor(access, exceptionClassName, String.class));
113+
114+
RuntimeReflection.register(clazz(access, exceptionClassName));
115+
RuntimeReflection.register(constructor(access, exceptionClassName, String.class));
112116
}
113117
}
114118

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025, 2025, 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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jdk;
26+
27+
import com.oracle.svm.core.annotate.Substitute;
28+
import com.oracle.svm.core.annotate.TargetClass;
29+
30+
@TargetClass(jdk.internal.util.Exceptions.class)
31+
@SuppressWarnings({"unused", "FieldCanBeLocal"})
32+
final class Target_jdk_internal_util_Exceptions {
33+
34+
/**
35+
* Setup is eagerly called in {@code com.oracle.svm.hosted.jdk.JDKInitializationFeature}.
36+
*/
37+
@Substitute
38+
public static void setup() {
39+
// do nothing
40+
}
41+
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ public void afterRegistration(AfterRegistrationAccess access) {
276276

277277
rci.initializeAtRunTime("jdk.internal.markdown.MarkdownTransformer", "Contains a static field with a DocTreeScanner which is initialized at run time");
278278

279+
/* Ensure "enhanced exception messages" are initialized (JDK 25+26, JDK-8348986). */
280+
var exceptionsClass = ReflectionUtil.lookupClass("jdk.internal.util.Exceptions");
281+
var exceptionsSetup = ReflectionUtil.lookupMethod(exceptionsClass, "setup");
282+
ReflectionUtil.invokeMethod(exceptionsSetup, null);
283+
279284
/*
280285
* The local class Holder in FallbackLinker#getInstance fails the build time initialization
281286
* starting JDK 22. There is no way to obtain a list of local classes using reflection. They

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ static void registerInitInetAddressIDs(DuringAnalysisAccess a) {
120120
RuntimeJNIAccess.register(constructor(a, "java.net.Inet6Address"));
121121
RuntimeJNIAccess.register(fields(a, "java.net.Inet6Address", "holder6"));
122122
RuntimeJNIAccess.register(fields(a, "java.net.Inet6Address$Inet6AddressHolder", "ipaddress", "scope_id", "scope_id_set", "scope_ifname"));
123+
124+
/* Used by getEnhancedExceptionsAllowed() in net_util.c (JDK-8348986) */
125+
RuntimeJNIAccess.register(fields(a, "jdk.internal.util.Exceptions", "enhancedNonSocketExceptionText"));
123126
}
124127

125128
private static void registerNetworkInterfaceInit(DuringAnalysisAccess a) {

0 commit comments

Comments
 (0)