Skip to content

Commit 103c6b8

Browse files
committed
Add missing reflection hint on Eclipse FileLocator
`PathMatchingResourcePatternResolver` is reflecting on `org.eclipse.core.runtime.FileLocator` and invoking methods on it for OSGi support. While this use case is highly unlikely in native images, registering the reflection entry by itself should be enough. Fixes gh-31271
1 parent 7af9ce4 commit 103c6b8

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2002-2023 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.aot.hint.support;
18+
19+
import org.springframework.aot.hint.RuntimeHints;
20+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
21+
import org.springframework.aot.hint.TypeReference;
22+
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
23+
24+
/**
25+
* {@link RuntimeHintsRegistrar} for {@link PathMatchingResourcePatternResolver}.
26+
* @author Brian Clozel
27+
*/
28+
class PathMatchingResourcePatternResolverRuntimeHints implements RuntimeHintsRegistrar {
29+
30+
@Override
31+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
32+
hints.reflection().registerType(TypeReference.of("org.eclipse.core.runtime.FileLocator"));
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=\
22
org.springframework.aot.hint.support.KotlinDetectorRuntimeHints,\
33
org.springframework.aot.hint.support.ObjectToObjectConverterRuntimeHints,\
4+
org.springframework.aot.hint.support.PathMatchingResourcePatternResolverRuntimeHints,\
45
org.springframework.aot.hint.support.SpringFactoriesLoaderRuntimeHints,\
56
org.springframework.aot.hint.support.SpringPropertiesRuntimeHints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2002-2023 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.aot.hint.support;
18+
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.aot.hint.RuntimeHints;
23+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
24+
import org.springframework.aot.hint.TypeReference;
25+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
26+
import org.springframework.core.io.support.SpringFactoriesLoader;
27+
import org.springframework.util.ClassUtils;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
/**
32+
* Tests for {@link PathMatchingResourcePatternResolverRuntimeHints}.
33+
*
34+
* @author Brian Clozel
35+
*/
36+
class PathMatchingResourcePatternResolverRuntimeHintsTests {
37+
38+
private RuntimeHints hints;
39+
40+
@BeforeEach
41+
void setup() {
42+
this.hints = new RuntimeHints();
43+
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
44+
.load(RuntimeHintsRegistrar.class).forEach(registrar -> registrar
45+
.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
46+
}
47+
48+
@Test
49+
void EclipseOsgiFileLocatorHasHints() {
50+
assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of("org.eclipse.core.runtime.FileLocator"))).accepts(this.hints);
51+
}
52+
53+
}

0 commit comments

Comments
 (0)