diff --git a/core/deployment/src/main/java/io/quarkus/deployment/recording/BytecodeRecorderImpl.java b/core/deployment/src/main/java/io/quarkus/deployment/recording/BytecodeRecorderImpl.java index ab33e0d209d4b4..651d21b79eddc5 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/recording/BytecodeRecorderImpl.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/recording/BytecodeRecorderImpl.java @@ -1200,6 +1200,7 @@ public void prepare(MethodContext context) { Set handledProperties = new HashSet<>(); Property[] desc = PropertyUtils.getPropertyDescriptors(param); + FieldsHelper fieldsHelper = new FieldsHelper(param.getClass()); for (Property i : desc) { if (!i.getDeclaringClass().getPackageName().startsWith("java.")) { // check if the getter is ignored @@ -1207,13 +1208,9 @@ public void prepare(MethodContext context) { continue; } // check if the matching field is ignored - try { - Field field = param.getClass().getDeclaredField(i.getName()); - if (ignoreField(field)) { - continue; - } - } catch (NoSuchFieldException ignored) { - + Field field = fieldsHelper.getDeclaredField(i.getName()); + if (field != null && ignoreField(field)) { + continue; } } Integer ctorParamIndex = constructorParamNameMap.remove(i.name); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/recording/FieldsHelper.java b/core/deployment/src/main/java/io/quarkus/deployment/recording/FieldsHelper.java new file mode 100644 index 00000000000000..9c14b226b2f871 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/recording/FieldsHelper.java @@ -0,0 +1,23 @@ +package io.quarkus.deployment.recording; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +final class FieldsHelper { + + private final Map fields; + + public FieldsHelper(final Class aClass) { + final Field[] declaredFields = aClass.getDeclaredFields(); + this.fields = new HashMap<>(declaredFields.length); + for (Field field : declaredFields) { + this.fields.put(field.getName(), field); + } + } + + //Returns the matching Field, or null if not existing + public Field getDeclaredField(final String name) { + return fields.get(name); + } +}