Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArC - improved error when unable to add a synthetic no-arg constructor #18805

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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