Skip to content

Commit fd9b376

Browse files
committed
Add GraalVM native reflection hints.
[resolves #549] Signed-off-by: Mark Paluch <[email protected]>
1 parent 0aa4854 commit fd9b376

File tree

2 files changed

+229
-0
lines changed

2 files changed

+229
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
[
2+
{
3+
"name": "[Lio.r2dbc.postgresql.codec.Box;",
4+
"unsafeAllocated": true
5+
},
6+
{
7+
"name": "[Lio.r2dbc.postgresql.codec.Circle;",
8+
"unsafeAllocated": true
9+
},
10+
{
11+
"name": "[Lio.r2dbc.postgresql.codec.Interval;",
12+
"unsafeAllocated": true
13+
},
14+
{
15+
"name": "[Lio.r2dbc.postgresql.codec.Line;",
16+
"unsafeAllocated": true
17+
},
18+
{
19+
"name": "[Lio.r2dbc.postgresql.codec.Lseg;",
20+
"unsafeAllocated": true
21+
},
22+
{
23+
"name": "[Lio.r2dbc.postgresql.codec.Path;",
24+
"unsafeAllocated": true
25+
},
26+
{
27+
"name": "[Lio.r2dbc.postgresql.codec.Point;",
28+
"unsafeAllocated": true
29+
},
30+
{
31+
"name": "[Lio.r2dbc.postgresql.codec.Polygon;",
32+
"unsafeAllocated": true
33+
},
34+
{
35+
"name": "[Ljava.lang.Boolean;",
36+
"unsafeAllocated": true
37+
},
38+
{
39+
"name": "[Ljava.lang.Byte;",
40+
"unsafeAllocated": true
41+
},
42+
{
43+
"name": "[Ljava.lang.Character;",
44+
"unsafeAllocated": true
45+
},
46+
{
47+
"name": "[Ljava.lang.Double;",
48+
"unsafeAllocated": true
49+
},
50+
{
51+
"name": "[Ljava.lang.Float;",
52+
"unsafeAllocated": true
53+
},
54+
{
55+
"name": "[Ljava.lang.Integer;",
56+
"unsafeAllocated": true
57+
},
58+
{
59+
"name": "[Ljava.lang.Long;",
60+
"unsafeAllocated": true
61+
},
62+
{
63+
"name": "[Ljava.lang.Short;",
64+
"unsafeAllocated": true
65+
},
66+
{
67+
"name": "[Ljava.lang.String;",
68+
"unsafeAllocated": true
69+
},
70+
{
71+
"name": "[Ljava.math.BigDecimal;",
72+
"unsafeAllocated": true
73+
},
74+
{
75+
"name": "[Ljava.math.BigInteger;",
76+
"unsafeAllocated": true
77+
},
78+
{
79+
"name": "[Ljava.net.InetAddress;",
80+
"unsafeAllocated": true
81+
},
82+
{
83+
"name": "[Ljava.net.URI;",
84+
"unsafeAllocated": true
85+
},
86+
{
87+
"name": "[Ljava.net.URL;",
88+
"unsafeAllocated": true
89+
},
90+
{
91+
"name": "[Ljava.nio.ByteBuffer;",
92+
"unsafeAllocated": true
93+
},
94+
{
95+
"name": "[Ljava.time.Instant;",
96+
"unsafeAllocated": true
97+
},
98+
{
99+
"name": "[Ljava.time.LocalDate;",
100+
"unsafeAllocated": true
101+
},
102+
{
103+
"name": "[Ljava.time.LocalDateTime;",
104+
"unsafeAllocated": true
105+
},
106+
{
107+
"name": "[Ljava.time.LocalTime;",
108+
"unsafeAllocated": true
109+
},
110+
{
111+
"name": "[Ljava.time.OffsetDateTime;",
112+
"unsafeAllocated": true
113+
},
114+
{
115+
"name": "[Ljava.time.OffsetTime;",
116+
"unsafeAllocated": true
117+
},
118+
{
119+
"name": "[Ljava.time.ZoneId;",
120+
"unsafeAllocated": true
121+
},
122+
{
123+
"name": "[Ljava.time.ZonedDateTime;",
124+
"unsafeAllocated": true
125+
},
126+
{
127+
"name": "[Ljava.util.Date;",
128+
"unsafeAllocated": true
129+
},
130+
{
131+
"name": "[Ljava.util.UUID;",
132+
"unsafeAllocated": true
133+
},
134+
{
135+
"name": "[[B",
136+
"unsafeAllocated": true
137+
},
138+
{
139+
"name": "[B",
140+
"unsafeAllocated": true
141+
},
142+
{
143+
"name": "java.net.InetSocketAddress",
144+
"unsafeAllocated": true
145+
}
146+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2022 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 io.r2dbc.postgresql.codec;
18+
19+
import io.r2dbc.postgresql.util.TestByteBufAllocator;
20+
import org.junit.jupiter.api.DynamicTest;
21+
import org.junit.jupiter.api.TestFactory;
22+
import org.springframework.asm.Type;
23+
import org.springframework.core.io.ClassPathResource;
24+
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
25+
26+
import java.io.IOException;
27+
import java.io.InputStream;
28+
import java.util.List;
29+
import java.util.Map;
30+
import java.util.stream.Stream;
31+
import java.util.stream.StreamSupport;
32+
33+
import static org.assertj.core.api.Assertions.as;
34+
import static org.assertj.core.api.Assertions.assertThat;
35+
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
36+
37+
/**
38+
* Tests for {@code reflect-config.json} to contain reflection hints for codecs.
39+
*/
40+
public class CodecReflectConfigTests {
41+
42+
@TestFactory
43+
Stream<DynamicTest> reflectionConfigContainsArrayCodecTypeHints() {
44+
45+
DefaultCodecs codecs = new DefaultCodecs(TestByteBufAllocator.TEST);
46+
47+
return StreamSupport.stream(codecs.spliterator(), false)
48+
.filter(ArrayCodec.class::isInstance)
49+
.map(ArrayCodec.class::cast)
50+
.map(it -> {
51+
return DynamicTest.dynamicTest(String.format("%s (%s)", it.getComponentType().getName(), it.getClass().getSimpleName()), () -> containsReflectionHint(it.getComponentType()));
52+
});
53+
}
54+
55+
void containsReflectionHint(Class<?> componentType) {
56+
57+
List<Map<String, Object>> list = readReflectConfig();
58+
59+
Type type = Type.getType(componentType);
60+
String lDotName = "[" + type.getDescriptor().replace('/', '.');
61+
String lSlashName = "[" + type.getDescriptor();
62+
String javaName = componentType.getName() + "[]";
63+
assertThat(list).describedAs("reflect-config.json entry for " + javaName).filteredOn(map -> {
64+
65+
Object name = map.get("name");
66+
return name.equals(lDotName) || name.equals(lSlashName) || name.equals(javaName);
67+
}).first(as(MAP)).describedAs("reflect-config.json entry for " + javaName).containsEntry("unsafeAllocated", true);
68+
}
69+
70+
@SuppressWarnings("unchecked")
71+
static List<Map<String, Object>> readReflectConfig() {
72+
73+
ObjectMapper mapper = new ObjectMapper();
74+
ClassPathResource resource = new ClassPathResource("META-INF/native-image/org.postgresql/r2dbc-postgresql/reflect-config.json");
75+
76+
try (InputStream is = resource.getInputStream()) {
77+
return mapper.readValue(is, List.class);
78+
} catch (IOException e) {
79+
throw new IllegalStateException(e);
80+
}
81+
}
82+
83+
}

0 commit comments

Comments
 (0)