Skip to content

Commit e787e3f

Browse files
committed
fix: test
1 parent 332c960 commit e787e3f

File tree

7 files changed

+30
-31
lines changed

7 files changed

+30
-31
lines changed

integration_tests/graalvm_tests/pom.xml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@
6363
<artifactId>fory-graalvm-feature</artifactId>
6464
<version>${project.version}</version>
6565
</dependency>
66-
<dependency>
67-
<groupId>org.graalvm.sdk</groupId>
68-
<artifactId>graal-sdk</artifactId>
69-
<version>23.0.0</version>
70-
<scope>provided</scope>
71-
</dependency>
7266
<dependency>
7367
<groupId>org.testng</groupId>
7468
<artifactId>testng</artifactId>
@@ -164,20 +158,14 @@
164158
<version>${native.maven.plugin.version}</version>
165159
<extensions>true</extensions>
166160
<executions>
161+
<!-- Build native image (no fork) to align with CI behavior -->
167162
<execution>
168163
<id>build-native</id>
169164
<goals>
170-
<goal>build</goal>
165+
<goal>compile-no-fork</goal>
171166
</goals>
172167
<phase>package</phase>
173168
</execution>
174-
<execution>
175-
<id>test-native</id>
176-
<goals>
177-
<goal>test</goal>
178-
</goals>
179-
<phase>test</phase>
180-
</execution>
181169
</executions>
182170
<configuration>
183171
<fallback>false</fallback>

java/fory-core/src/test/java/org/apache/fory/util/GraalvmSupportRecordTest.java renamed to integration_tests/graalvm_tests/src/test/java/org/apache/fory/util/GraalvmSupportRecordTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ public void testIsRecordConstructorPublicAccessible_WithString() {
6666
}
6767

6868
@Test
69-
public void testObjectCreators_IsProblematicForCreation_WithRegularClass() {
69+
public void testObjectCreators_ReflectiveInstantiationFlag_WithRegularClass() {
7070
boolean result = GraalvmSupport.needReflectionRegisterForCreation(RegularClass.class);
7171
Assert.assertFalse(
72-
result, "RegularClass with no-arg constructor should not be problematic for creation");
72+
result,
73+
"RegularClass with no-arg constructor does not require reflective instantiation registration");
7374
}
7475

7576
@Test
@@ -109,3 +110,4 @@ public void testRecordUtilsIntegration() {
109110
Assert.assertFalse(GraalvmSupport.isRecordConstructorPublicAccessible(String.class));
110111
}
111112
}
113+

java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,8 +1794,10 @@ public void ensureSerializersCompiled() {
17941794
try {
17951795
fory.getJITContext().lock();
17961796
Serializers.newSerializer(fory, LambdaSerializer.STUB_LAMBDA_CLASS, LambdaSerializer.class);
1797-
Serializers.newSerializer(
1798-
fory, JdkProxySerializer.SUBT_PROXY.getClass(), JdkProxySerializer.class);
1797+
if (!GraalvmSupport.isGraalRuntime()) {
1798+
Serializers.newSerializer(
1799+
fory, JdkProxySerializer.SUBT_PROXY.getClass(), JdkProxySerializer.class);
1800+
}
17991801
classInfoMap.forEach(
18001802
(cls, classInfo) -> {
18011803
GraalvmSupport.registerClassForGraalvm(cls, fory.getConfig().getConfigHash());

java/fory-core/src/main/java/org/apache/fory/serializer/JdkProxySerializer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.fory.memory.Platform;
2929
import org.apache.fory.reflect.ReflectionUtils;
3030
import org.apache.fory.resolver.RefResolver;
31+
import org.apache.fory.util.GraalvmSupport;
3132
import org.apache.fory.util.Preconditions;
3233

3334
/** Serializer for jdk {@link Proxy}. */
@@ -62,7 +63,11 @@ private interface StubInterface {
6263
public JdkProxySerializer(Fory fory, Class cls) {
6364
super(fory, cls);
6465
if (cls != ReplaceStub.class) {
65-
Preconditions.checkArgument(ReflectionUtils.isJdkProxy(cls), "Require a jdk proxy class");
66+
// Skip proxy class validation in GraalVM native image runtime to avoid issues with proxy
67+
// detection
68+
if (!GraalvmSupport.isGraalRuntime()) {
69+
Preconditions.checkArgument(ReflectionUtils.isJdkProxy(cls), "Require a jdk proxy class");
70+
}
6671
}
6772
}
6873

java/fory-core/src/main/java/org/apache/fory/util/GraalvmSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ public static boolean isRecordConstructorPublicAccessible(Class<?> type) {
234234
}
235235

236236
/**
237-
* Checks if a class is problematic for object creation and requires special handling in GraalVM.
237+
* Checks whether a class requires reflective instantiation handling in GraalVM.
238238
*
239-
* <p>A class is considered problematic if it lacks a public no-arg constructor and would
240-
* typically require ReflectionFactory or unsafe allocation for instantiation.
239+
* <p>Returns true when the class does not expose an accessible no-arg constructor and therefore
240+
* needs reflective registration for instantiation during native image builds.
241241
*
242242
* @param type the class to check
243-
* @return true if the class is problematic for creation, false otherwise
243+
* @return true if reflective instantiation handling is required, false otherwise
244244
*/
245245
public static boolean needReflectionRegisterForCreation(Class<?> type) {
246246
if (type.isInterface()

java/fory-graalvm-feature/src/main/java/org/apache/fory/graalvm/feature/ForyGraalVMFeature.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
* to ensure Fory serialization works correctly at runtime. It handles:
3434
*
3535
* <ul>
36-
* <li>Registering problematic classes for unsafe allocation
36+
* <li>Registering classes that require reflective instantiation (no accessible no-arg
37+
* constructor)
3738
* <li>Registering field reflection access for serialization
3839
* <li>Registering proxy interfaces for dynamic proxy creation
3940
* </ul>
@@ -68,7 +69,7 @@ public void duringAnalysis(DuringAnalysisAccess access) {
6869
}
6970

7071
public String getDescription() {
71-
return "Fory GraalVM Feature: Registers classes for serialization, proxying, and unsafe allocation.";
72+
return "Fory GraalVM Feature: Registers classes for serialization and proxy support.";
7273
}
7374

7475
private void handleForyClass(Class<?> clazz) {
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,28 @@ public void tearDown() {
7373
public void testGetDescription() {
7474
String description = feature.getDescription();
7575
assertEquals(
76-
"Fory GraalVM Feature: Registers classes for serialization, proxying, and unsafe allocation.",
76+
"Fory GraalVM Feature: Registers classes for serialization and proxy support.",
7777
description);
7878
}
7979

8080
@Test
81-
public void testObjectCreatorsProblematicDetection() {
81+
public void testObjectCreatorsDetection() {
8282
assertTrue(
8383
GraalvmSupport.needReflectionRegisterForCreation(
8484
PrivateParameterizedConstructorClass.class),
85-
"Class without no-arg constructor should be problematic");
85+
"Class without no-arg constructor requires reflective instantiation registration");
8686

8787
assertFalse(
8888
GraalvmSupport.needReflectionRegisterForCreation(PublicNoArgConstructorClass.class),
89-
"Public no-arg constructor should not be problematic");
89+
"Public no-arg constructor does not require reflective instantiation registration");
9090

9191
assertFalse(
9292
GraalvmSupport.needReflectionRegisterForCreation(ProtectedNoArgConstructorClass.class),
93-
"Protected no-arg constructor should not be problematic");
93+
"Protected no-arg constructor does not require reflective instantiation registration");
9494

9595
assertFalse(
9696
GraalvmSupport.needReflectionRegisterForCreation(SampleEnum.class),
97-
"Enums should not be considered problematic");
97+
"Enums do not require reflective instantiation registration");
9898
}
9999

100100
@Test
@@ -165,3 +165,4 @@ public void testClearRegistrationsResetsState() {
165165
}
166166
}
167167
}
168+

0 commit comments

Comments
 (0)