This is an automated email from the ASF dual-hosted git repository. joerghoh pushed a commit to branch SLING-12483-isRecord in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git
commit e297671d24b2e842d51dc07009c738728f7065ea Author: Joerg Hoh <[email protected]> AuthorDate: Tue Nov 12 21:41:43 2024 +0100 SLING-12483 try to load the Record class on class init --- .../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); } /**
