From 0e01070d5f3660ee67291bd88da1d9bc4bf98a6e Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 6 Apr 2022 13:38:47 +0200 Subject: [PATCH] ArC - custom error message when kotlin List used with All qualifier - resolves #24766 --- .../quarkus/arc/deployment/ArcProcessor.java | 19 ++++++++++++++++--- .../io/quarkus/arc/processor/DotNames.java | 4 ++-- .../arc/processor/SubclassGenerator.java | 3 +-- 3 files changed, 19 insertions(+), 7 deletions(-) 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 6b2df3ce56c7f..f8f0e332c0455 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 @@ -441,9 +441,22 @@ public ObserverRegistrationPhaseBuildItem registerSyntheticObservers(BeanRegistr // Note that at this point we can be sure that the required type is List<> Type typeParam = injectionPoint.getType().asParameterizedType().arguments().get(0); if (typeParam.kind() == Type.Kind.WILDCARD_TYPE) { - validationErrors.produce(new ValidationErrorBuildItem( - new DefinitionException( - "Wildcard is not a legal type argument for " + injectionPoint.getTargetInfo()))); + ClassInfo declaringClass; + if (injectionPoint.isField()) { + declaringClass = injectionPoint.getTarget().asField().declaringClass(); + } else { + declaringClass = injectionPoint.getTarget().asMethod().declaringClass(); + } + if (declaringClass.classAnnotation(DotNames.KOTLIN_METADATA_ANNOTATION) != null) { + validationErrors.produce(new ValidationErrorBuildItem( + new DefinitionException( + "kotlin.collections.List cannot be used together with the @All qualifier, please use MutableList or java.util.List instead: " + + injectionPoint.getTargetInfo()))); + } else { + validationErrors.produce(new ValidationErrorBuildItem( + new DefinitionException( + "Wildcard is not a legal type argument for " + injectionPoint.getTargetInfo()))); + } } else if (typeParam.kind() == Type.Kind.TYPE_VARIABLE) { validationErrors.produce(new ValidationErrorBuildItem(new DefinitionException( "Type variable is not a legal type argument for " + injectionPoint.getTargetInfo()))); diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DotNames.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DotNames.java index 2aa648d90dd37..e7272bf380d54 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DotNames.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DotNames.java @@ -128,6 +128,8 @@ public final class DotNames { public static final DotName IDENTIFIED = create(Identified.class); public static final DotName INSTANCE_HANDLE = create(InstanceHandle.class); public static final DotName NO_CLASS_INTERCEPTORS = create(NoClassInterceptors.class); + public static final DotName DEPRECATED = create(Deprecated.class); + public static final DotName KOTLIN_METADATA_ANNOTATION = create("kotlin.Metadata"); public static final DotName BOOLEAN = create(Boolean.class); public static final DotName BYTE = create(Byte.class); @@ -139,8 +141,6 @@ public final class DotNames { public static final DotName SHORT = create(Short.class); public static final DotName STRING = create(String.class); - public static final DotName DEPRECATED = create(Deprecated.class); - private DotNames() { } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/SubclassGenerator.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/SubclassGenerator.java index 9fe7af99568af..71cf4847d8a1c 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/SubclassGenerator.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/SubclassGenerator.java @@ -65,7 +65,6 @@ public class SubclassGenerator extends AbstractGenerator { private static final DotName JAVA_LANG_THROWABLE = DotNames.create(Throwable.class.getName()); private static final DotName JAVA_LANG_EXCEPTION = DotNames.create(Exception.class.getName()); private static final DotName JAVA_LANG_RUNTIME_EXCEPTION = DotNames.create(RuntimeException.class.getName()); - private static final DotName KOTLIN_METADATA_ANNOTATION = DotNames.create("kotlin.Metadata"); static final String SUBCLASS_SUFFIX = "_Subclass"; static final String DESTROY_METHOD_NAME = "arc$destroy"; @@ -750,7 +749,7 @@ private void createInterceptedMethod(ClassOutput classOutput, BeanInfo bean, Met // catch exceptions declared on the original method boolean addCatchRuntimeException = true; boolean addCatchException = true; - boolean isKotlin = method.declaringClass().classAnnotation(KOTLIN_METADATA_ANNOTATION) != null; + boolean isKotlin = method.declaringClass().classAnnotation(DotNames.KOTLIN_METADATA_ANNOTATION) != null; Set declaredExceptions = new LinkedHashSet<>(method.exceptions().size()); for (Type declaredException : method.exceptions()) { declaredExceptions.add(declaredException.name());