This is an automated email from the ASF dual-hosted git repository.
joerghoh pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git
The following commit(s) were added to refs/heads/master by this push:
new 365374f SLING-12483 load the Record class on class init (#61)
365374f is described below
commit 365374f7cefb03c8e864891db8a2991d27d16338
Author: Jörg Hoh <[email protected]>
AuthorDate: Thu Nov 14 12:54:33 2024 +0100
SLING-12483 load the Record class on class init (#61)
---
.../org/apache/sling/models/impl/ReflectionUtil.java | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
b/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
index e66c2a3..7cd6b0a 100644
--- a/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
+++ b/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
@@ -34,6 +34,18 @@ import
org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
*/
public final class ReflectionUtil {
+ static Class<?> recordType;
+
+ static {
+ try {
+ recordType = Class.forName("java.lang.Record");
+ } catch (ClassNotFoundException e) {
+ // this happens when running with Java11, which is supported, but
+ // of course does not have support for Record types
+ recordType = null;
+ }
+ }
+
private ReflectionUtil() {
// static methods only
}
@@ -123,14 +135,10 @@ public final class ReflectionUtil {
}
public static boolean isRecord(Class<?> checkedType) {
- try {
- Class<?> recordType = Class.forName("java.lang.Record");
- return recordType.isAssignableFrom(checkedType);
- } catch (
- @SuppressWarnings("squid:S1166")
- ClassNotFoundException exception) {
+ if (recordType == null) {
return false;
}
+ return recordType.isAssignableFrom(checkedType);
}
/**