diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveFieldBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveFieldBuildItem.java index 9738b2256b474..28ae2f07a6b94 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveFieldBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveFieldBuildItem.java @@ -10,13 +10,24 @@ public final class ReflectiveFieldBuildItem extends MultiBuildItem { final String declaringClass; final String name; + final String reason; - public ReflectiveFieldBuildItem(FieldInfo field) { + public ReflectiveFieldBuildItem(String reason, FieldInfo field) { + this.reason = reason; this.name = field.name(); this.declaringClass = field.declaringClass().name().toString(); } + public ReflectiveFieldBuildItem(FieldInfo field) { + this(null, field); + } + public ReflectiveFieldBuildItem(Field field) { + this(null, field); + } + + public ReflectiveFieldBuildItem(String reason, Field field) { + this.reason = reason; this.name = field.getName(); this.declaringClass = field.getDeclaringClass().getName(); } @@ -28,4 +39,8 @@ public String getDeclaringClass() { public String getName() { return name; } + + public String getReason() { + return reason; + } } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveMethodBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveMethodBuildItem.java index d22291618f03b..48692063f5344 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveMethodBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveMethodBuildItem.java @@ -3,7 +3,6 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.Objects; -import java.util.stream.Collectors; import org.jboss.jandex.MethodInfo; @@ -58,7 +57,7 @@ public ReflectiveMethodBuildItem(String reason, String declaringClass, String na } public ReflectiveMethodBuildItem(boolean queryOnly, String declaringClass, String name, - String... params) { + String... params) { this(null, queryOnly, declaringClass, name, params); } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageReflectConfigStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageReflectConfigStep.java index 989c9e27d6d65..efe9a04ac4ddd 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageReflectConfigStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageReflectConfigStep.java @@ -54,11 +54,13 @@ void generateReflectConfig(BuildProducer reflectConf for (ServiceProviderBuildItem i : serviceProviderBuildItems) { for (String provider : i.providers()) { // Register the nullary constructor - addReflectiveMethod(reflectiveClasses, new ReflectiveMethodBuildItem("Class registered as provider", provider, "", new String[0])); + addReflectiveMethod(reflectiveClasses, + new ReflectiveMethodBuildItem("Class registered as provider", provider, "", new String[0])); // Register public provider() method for lookkup to avoid throwing a MissingReflectionRegistrationError at run time. // See ServiceLoader#loadProvider and ServiceLoader#findStaticProviderMethod. addReflectiveMethod(reflectiveClasses, - new ReflectiveMethodBuildItem("Class registered as provider", true, provider, "provider", new String[0])); + new ReflectiveMethodBuildItem("Class registered as provider", true, provider, "provider", + new String[0])); } } @@ -233,6 +235,13 @@ public void addReflectiveField(Map reflectiveClasses, Re reflectiveClasses.put(cl, existing = new ReflectionInfo()); } existing.fieldSet.add(fieldInfo.getName()); + String reason = fieldInfo.getReason(); + if (reason != null) { + if (existing.reasons == null) { + existing.reasons = new HashSet<>(); + } + existing.reasons.add(reason); + } } static final class ReflectionInfo { diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java index cc1213e8311ea..f6853f9f6c163 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java @@ -548,7 +548,7 @@ public void registerMethod(MethodInfo methodInfo) { @Override public void registerField(FieldInfo fieldInfo) { - reflectiveFields.produce(new ReflectiveFieldBuildItem(fieldInfo)); + reflectiveFields.produce(new ReflectiveFieldBuildItem(getClass().getName(), fieldInfo)); } @Override diff --git a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java index 843879361cdff..2558695960f14 100644 --- a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java +++ b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java @@ -498,7 +498,7 @@ public void build( for (AnnotationInstance annotation : annotationInstances) { if (annotation.target().kind() == AnnotationTarget.Kind.FIELD) { contributeClass(classNamesToBeValidated, indexView, annotation.target().asField().declaringClass().name()); - reflectiveFields.produce(new ReflectiveFieldBuildItem(annotation.target().asField())); + reflectiveFields.produce(new ReflectiveFieldBuildItem(getClass().getName(), annotation.target().asField())); contributeClassMarkedForCascadingValidation(classNamesToBeValidated, indexView, consideredAnnotation, annotation.target().asField().type()); } else if (annotation.target().kind() == AnnotationTarget.Kind.METHOD) { @@ -528,7 +528,7 @@ public void build( AnnotationTarget enclosingTarget = annotation.target().asType().enclosingTarget(); if (enclosingTarget.kind() == AnnotationTarget.Kind.FIELD) { contributeClass(classNamesToBeValidated, indexView, enclosingTarget.asField().declaringClass().name()); - reflectiveFields.produce(new ReflectiveFieldBuildItem(enclosingTarget.asField())); + reflectiveFields.produce(new ReflectiveFieldBuildItem(getClass().getName(), enclosingTarget.asField())); if (annotation.target().asType().target() != null) { contributeClassMarkedForCascadingValidation(classNamesToBeValidated, indexView, consideredAnnotation, diff --git a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java index 6ea3e98035b38..bbb443b535381 100644 --- a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java +++ b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java @@ -273,7 +273,8 @@ void register( // make sure we register the constructors and methods marked with @JsonCreator for reflection for (AnnotationInstance creatorInstance : index.getAnnotations(JSON_CREATOR)) { if (METHOD == creatorInstance.target().kind()) { - reflectiveMethod.produce(new ReflectiveMethodBuildItem(getClass().getName(), creatorInstance.target().asMethod())); + reflectiveMethod + .produce(new ReflectiveMethodBuildItem(getClass().getName(), creatorInstance.target().asMethod())); } }