Skip to content

Commit 2d05f2e

Browse files
committed
SerializableTypeWrapper detects Graal through system property as well
Issue: SPR-17136
1 parent 4a18488 commit 2d05f2e

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@
3838
*/
3939
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
4040

41-
// See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java
42-
private static final boolean inImageCode = (System.getProperty("org.graalvm.nativeimage.imagecode") != null);
43-
44-
4541
public DefaultParameterNameDiscoverer() {
46-
if (!inImageCode) {
42+
if (!GraalDetector.inImageCode()) {
4743
if (KotlinDetector.isKotlinReflectPresent()) {
4844
addDiscoverer(new KotlinReflectionParameterNameDiscoverer());
4945
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2002-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.core;
18+
19+
/**
20+
* A common delegate for detecting a GraalVM native image environment.
21+
*
22+
* @author Juergen Hoeller
23+
* @author Sebastien Deleuze
24+
* @since 5.1
25+
*/
26+
abstract class GraalDetector {
27+
28+
// See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java
29+
private static final boolean imageCode = (System.getProperty("org.graalvm.nativeimage.imagecode") != null);
30+
31+
32+
/**
33+
* Return whether this runtime environment lives within a native image.
34+
*/
35+
public static boolean inImageCode() {
36+
return imageCode;
37+
}
38+
39+
}

spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static Type forTypeProvider(TypeProvider provider) {
108108
// No serializable type wrapping necessary (e.g. for java.lang.Class)
109109
return providedType;
110110
}
111-
if (!Serializable.class.isAssignableFrom(Class.class)) {
111+
if (GraalDetector.inImageCode() || !Serializable.class.isAssignableFrom(Class.class)) {
112112
// Let's skip any wrapping attempts if types are generally not serializable in
113113
// the current runtime environment (even java.lang.Class itself, e.g. on Graal)
114114
return providedType;

0 commit comments

Comments
 (0)