Skip to content

Commit

Permalink
Merge pull request #32105 from Sgitario/31043_disable
Browse files Browse the repository at this point in the history
Disable validation of JAXBContext by default
  • Loading branch information
gsmet committed Mar 25, 2023
2 parents 4c381bb + 8a199fc commit 7e288ad
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 25 deletions.
7 changes: 7 additions & 0 deletions extensions/jaxb/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Duser.language=en</argLine>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,35 +316,19 @@ FilteredJaxbClassesToBeBoundBuildItem filterBoundClasses(

@BuildStep
@Record(ExecutionTime.STATIC_INIT)
void validateDefaultJaxbContext(
void bindClassesToJaxbContext(
JaxbConfig config,
FilteredJaxbClassesToBeBoundBuildItem filteredClassesToBeBound,
SynthesisFinishedBuildItem beanContainerState,
JaxbContextConfigRecorder jaxbContextConfig /* Force the build time container to invoke this method */) {

if (config.validateJaxbContext) {
final BeanResolver beanResolver = beanContainerState.getBeanResolver();
final Set<BeanInfo> beans = beanResolver
.resolveBeans(Type.create(DotName.createSimple(JAXBContext.class), org.jboss.jandex.Type.Kind.CLASS));
if (!beans.isEmpty()) {
jaxbContextConfig.addClassesToBeBound(filteredClassesToBeBound.getClasses());
final BeanInfo bean = beanResolver.resolveAmbiguity(beans);
if (bean.isDefaultBean()) {
/*
* Validate the default JAXB context at build time and fail early.
* Do this only if the user application actually requires the default JAXBContext bean
*/
try {
JAXBContext.newInstance(filteredClassesToBeBound.getClasses().toArray(new Class[0]));
} catch (JAXBException e) {
/*
* Producing a ValidationErrorBuildItem would perhaps be more natural here,
* but doing so causes a cycle between this and reactive JAXB extension
* Throwing from here works well too
*/
throw new DeploymentException("Failed to create or validate the default JAXBContext", e);
}
}
final BeanResolver beanResolver = beanContainerState.getBeanResolver();
final Set<BeanInfo> beans = beanResolver
.resolveBeans(Type.create(DotName.createSimple(JAXBContext.class), org.jboss.jandex.Type.Kind.CLASS));
if (!beans.isEmpty()) {
jaxbContextConfig.addClassesToBeBound(filteredClassesToBeBound.getClasses());
if (config.validateJaxbContext) {
validateJaxbContext(filteredClassesToBeBound, beanResolver, beans);
}
}
}
Expand All @@ -354,6 +338,27 @@ void registerProduces(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
additionalBeans.produce(new AdditionalBeanBuildItem(JaxbContextProducer.class));
}

private void validateJaxbContext(FilteredJaxbClassesToBeBoundBuildItem filteredClassesToBeBound, BeanResolver beanResolver,
Set<BeanInfo> beans) {
final BeanInfo bean = beanResolver.resolveAmbiguity(beans);
if (bean.isDefaultBean()) {
/*
* Validate the default JAXB context at build time and fail early.
* Do this only if the user application actually requires the default JAXBContext bean
*/
try {
JAXBContext.newInstance(filteredClassesToBeBound.getClasses().toArray(new Class[0]));
} catch (JAXBException e) {
/*
* Producing a ValidationErrorBuildItem would perhaps be more natural here,
* but doing so causes a cycle between this and reactive JAXB extension
* Throwing from here works well too
*/
throw new DeploymentException("Failed to create or validate the default JAXBContext", e);
}
}
}

private void handleJaxbFile(Path p, BuildProducer<NativeImageResourceBuildItem> resource,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
List<String> classesToBeBound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ConflictingModelClassesMarshalerOnlyTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withConfigurationResource("application-enable-validation.properties")
.withApplicationRoot((jar) -> jar
.addClasses(
io.quarkus.jaxb.deployment.one.Model.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ConflictingModelClassesTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withConfigurationResource("application-enable-validation.properties")
.withApplicationRoot((jar) -> jar
.addClasses(
io.quarkus.jaxb.deployment.one.Model.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.jaxb.validate-jaxb-context=true
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class JaxbConfig {
/**
* If enabled, it will validate the default JAXB context at build time.
*/
@ConfigItem(defaultValue = "true")
@ConfigItem(defaultValue = "false")
public boolean validateJaxbContext;

/**
Expand Down

0 comments on commit 7e288ad

Please sign in to comment.