Skip to content

Commit 9b4e0e9

Browse files
committed
Add missing hint for converting String to URI
Closes gh-30627
1 parent 071d6a2 commit 9b4e0e9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.List;
2222

2323
import org.springframework.aot.hint.ExecutableMode;
24+
import org.springframework.aot.hint.MemberCategory;
25+
import org.springframework.aot.hint.ReflectionHints;
2426
import org.springframework.aot.hint.RuntimeHints;
2527
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2628
import org.springframework.aot.hint.TypeReference;
@@ -37,15 +39,17 @@ class ObjectToObjectConverterRuntimeHints implements RuntimeHintsRegistrar {
3739

3840
@Override
3941
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
42+
ReflectionHints reflectionHints = hints.reflection();
4043
TypeReference sqlDateTypeReference = TypeReference.of("java.sql.Date");
41-
hints.reflection().registerTypeIfPresent(classLoader, sqlDateTypeReference.getName(), hint -> hint
44+
reflectionHints.registerTypeIfPresent(classLoader, sqlDateTypeReference.getName(), hint -> hint
4245
.withMethod("toLocalDate", Collections.emptyList(), ExecutableMode.INVOKE)
4346
.onReachableType(sqlDateTypeReference)
4447
.withMethod("valueOf", List.of(TypeReference.of(LocalDate.class)), ExecutableMode.INVOKE)
4548
.onReachableType(sqlDateTypeReference));
4649

47-
hints.reflection().registerTypeIfPresent(classLoader, "org.springframework.http.HttpMethod",
50+
reflectionHints.registerTypeIfPresent(classLoader, "org.springframework.http.HttpMethod",
4851
builder -> builder.withMethod("valueOf", List.of(TypeReference.of(String.class)), ExecutableMode.INVOKE));
52+
reflectionHints.registerTypeIfPresent(classLoader, "java.net.URI", MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
4953
}
5054

5155
}

spring-core/src/test/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHintsTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.aot.hint.support;
1818

19+
import java.net.URI;
1920
import java.time.LocalDate;
2021

2122
import org.junit.jupiter.api.BeforeEach;
@@ -52,4 +53,9 @@ void javaSqlDateHasHints() throws NoSuchMethodException {
5253
assertThat(RuntimeHintsPredicates.reflection().onMethod(java.sql.Date.class.getMethod("valueOf", LocalDate.class))).accepts(this.hints);
5354
}
5455

56+
@Test
57+
void uriHasHints() throws NoSuchMethodException {
58+
assertThat(RuntimeHintsPredicates.reflection().onConstructor(URI.class.getConstructor(String.class))).accepts(this.hints);
59+
}
60+
5561
}

0 commit comments

Comments
 (0)