Skip to content

Commit 506b760

Browse files
committed
Add missing reflection hints for JdbcUtils
This commit adds the missing reflection hints for `JdbcUtils`, as this class reflects on `java.sql.Types` public fields. Fixes gh-35674
1 parent 7adcd99 commit 506b760

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2025-present 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+
* https://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.jdbc.support;
18+
19+
import java.sql.Types;
20+
21+
import org.jspecify.annotations.Nullable;
22+
23+
import org.springframework.aot.hint.MemberCategory;
24+
import org.springframework.aot.hint.RuntimeHints;
25+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
26+
27+
/**
28+
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints for
29+
* {@link JdbcUtils}.
30+
* @author Brian Clozel
31+
* @since 6.2.13
32+
*/
33+
class JdbcUtilsRuntimeHints implements RuntimeHintsRegistrar {
34+
35+
@Override
36+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
37+
hints.reflection().registerType(Types.class, MemberCategory.ACCESS_PUBLIC_FIELDS);
38+
}
39+
40+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2-
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryRuntimeHints
2+
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryRuntimeHints,\
3+
org.springframework.jdbc.support.JdbcUtilsRuntimeHints
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025-present 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+
* https://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.jdbc.support;
18+
19+
import java.lang.reflect.Field;
20+
import java.sql.Types;
21+
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
24+
25+
import org.springframework.aot.hint.RuntimeHints;
26+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
27+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
28+
import org.springframework.beans.factory.aot.AotServices;
29+
import org.springframework.util.ClassUtils;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
/**
34+
* Tests for {@link JdbcUtilsRuntimeHints}.
35+
*/
36+
class JdbcUtilsRuntimeHintsTests {
37+
38+
private final RuntimeHints hints = new RuntimeHints();
39+
40+
@BeforeEach
41+
void setup() {
42+
AotServices.factories().load(RuntimeHintsRegistrar.class)
43+
.forEach(registrar -> registrar.registerHints(this.hints,
44+
ClassUtils.getDefaultClassLoader()));
45+
}
46+
47+
@Test
48+
void sqlTypesShouldHaveFieldAccess() {
49+
for (Field field : Types.class.getFields()) {
50+
assertThat(RuntimeHintsPredicates.reflection()
51+
.onFieldAccess(field)).accepts(this.hints);
52+
}
53+
}
54+
55+
}

0 commit comments

Comments
 (0)