Skip to content

Commit

Permalink
ArC - custom error message when kotlin List used with All qualifier
Browse files Browse the repository at this point in the history
- resolves #24766
  • Loading branch information
mkouba committed Apr 6, 2022
1 parent 2b8a6da commit 0e01070
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<DotName> declaredExceptions = new LinkedHashSet<>(method.exceptions().size());
for (Type declaredException : method.exceptions()) {
declaredExceptions.add(declaredException.name());
Expand Down

0 comments on commit 0e01070

Please sign in to comment.