Skip to content

Commit

Permalink
Merge pull request #18805 from mkouba/issue-18736
Browse files Browse the repository at this point in the history
ArC - improved error when unable to add a synthetic no-arg constructor
  • Loading branch information
mkouba authored Jul 19, 2021
2 parents 71790a5 + bde03df commit df12275
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,7 @@ static void validateBean(BeanInfo bean, List<Throwable> errors, List<BeanDeploym
}

} else {
errors.add(new DeploymentException(
"It's not possible to add a synthetic constructor with no parameters to the unproxyable bean class: "
+
beanClass));
errors.add(cannotAddSyntheticNoArgsConstructor(beanClass));
}
} else {
errors.add(new DeploymentException(String
Expand Down Expand Up @@ -764,9 +761,7 @@ static void validateBean(BeanInfo bean, List<Throwable> errors, List<BeanDeploym
classesReceivingNoArgsCtor.add(returnTypeClass.name());
}
} else {
errors.add(new DeploymentException(String
.format("It's not possible to add a synthetic constructor with no parameters to the unproxyable return type of "
+ bean)));
errors.add(cannotAddSyntheticNoArgsConstructor(returnTypeClass));
}
} else {
errors.add(new DefinitionException(String
Expand Down Expand Up @@ -810,10 +805,7 @@ static void validateBean(BeanInfo bean, List<Throwable> errors, List<BeanDeploym
classesReceivingNoArgsCtor.add(beanClass.name());
}
} else {
errors.add(new DeploymentException(
"It's not possible to add a synthetic constructor with no parameters to the unproxyable bean class: "
+
beanClass));
errors.add(cannotAddSyntheticNoArgsConstructor(beanClass));
}
} else {
errors.add(new DeploymentException(String
Expand All @@ -824,6 +816,11 @@ static void validateBean(BeanInfo bean, List<Throwable> errors, List<BeanDeploym
}
}

private static DeploymentException cannotAddSyntheticNoArgsConstructor(ClassInfo beanClass) {
String message = "It's not possible to automatically add a synthetic no-args constructor to an unproxyable bean class. You need to manually add a non-private no-args constructor to %s in order to fulfill the requirements for normal scoped/intercepted/decorated beans.";
return new DeploymentException(String.format(message, beanClass));
}

private static void fetchType(Type type, BeanDeployment beanDeployment) {
if (type == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public class QuarkusUnitTest
private List<ClassLoaderEventListener> classLoadListeners = new ArrayList<>();

public QuarkusUnitTest setExpectedException(Class<? extends Throwable> expectedException) {
return setExpectedException(expectedException, false);
}

public QuarkusUnitTest setExpectedException(Class<? extends Throwable> expectedException, boolean logMessage) {
return assertException(t -> {
Throwable i = t;
boolean found = false;
Expand All @@ -130,8 +134,10 @@ public QuarkusUnitTest setExpectedException(Class<? extends Throwable> expectedE
}
i = i.getCause();
}

assertTrue(found, "Build failed with wrong exception, expected " + expectedException + " but got " + t);
if (found && logMessage) {
System.out.println("Build failed with the expected exception:" + i);
}
assertTrue(found, "Build failed with a wrong exception, expected " + expectedException + " but got " + t);
});
}

Expand Down

0 comments on commit df12275

Please sign in to comment.