Repository: quarkusio/quarkus
Issue: `quarkus-jaxb` loads entity classes at build time even though no default JAXBContext will be created within the application

### Describe the bug

I am working on a test within Quarkiverse CXF that makes sure that SOAP service methods having runtime initialized arguments work. Those arguments typically have JAXB annotations and so they are catched by JaxbProcessor when collecting classes for the default JAXBContext. If some of those arguments has (for whatever reason) runtime init set, then the native build fails with the following exception:

```
[WARN] [stderr] Error: Classes that should be initialized at run time got initialized during image building:
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:73)
[WARN] [stderr]  io.quarkiverse.cxf.client.it.rtinit.Result the class was requested to be initialized at run time (from command line with 'io.quarkiverse.cxf.client.it.rtinit.Result'). To see why io.quarkiverse.cxf.client.it.rtinit.Result got initialized use --trace-class-initialization=io.quarkiverse.cxf.client.it.rtinit.Result
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ProvenSafeClassInitializationSupport.checkDelayedInitialization(ProvenSafeClassInitializationSupport.java:273)
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:164)
[INFO] [stdout] ------------------------------------------------------------------------------------------------------------------------
[WARN] [stderr] io.quarkiverse.cxf.client.it.rtinit.Operands the class was requested to be initialized at run time (from command line with 'io.quarkiverse.cxf.client.it.rtinit.Operands'). io.quarkus.runner.ApplicationImpl caused initialization of this class with the following trace: 
[WARN] [stderr]         at io.quarkiverse.cxf.client.it.rtinit.Operands.<clinit>(Operands.java)
[WARN] [stderr]         at java.lang.Class.forName0(Unknown Source)
[WARN] [stderr]         at java.lang.Class.forName(Class.java:467)
[WARN] [stderr]         at io.quarkus.deployment.steps.JaxbProcessor$setupJaxbContextConfig1556898737.deploy_0(Unknown Source)
[WARN] [stderr]         at io.quarkus.deployment.steps.JaxbProcessor$setupJaxbContextConfig1556898737.deploy(Unknown Source)
[WARN] [stderr]         at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
[WARN] [stderr] 
[WARN] [stderr] To see how the classes got initialized, use --trace-class-initialization=io.quarkiverse.cxf.client.it.rtinit.Result
[WARN] [stderr] com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:748)
[WARN] [stderr]  io.quarkiverse.cxf.client.it.rtinit.Result the class was requested to be initialized at run time (from command line with 'io.quarkiverse.cxf.client.it.rtinit.Result'). To see why io.quarkiverse.cxf.client.it.rtinit.Result got initialized use --trace-class-initialization=io.quarkiverse.cxf.client.it.rtinit.Result
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:85)
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:748)
[WARN] [stderr]         at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:162)
[WARN] [stderr] io.quarkiverse.cxf.client.it.rtinit.Operands the class was requested to be initialized at run time (from command line with 'io.quarkiverse.cxf.client.it.rtinit.Operands'). io.quarkus.runner.ApplicationImpl caused initialization of this class with the following trace: 
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:745)
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:578)
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
[WARN] [stderr]         at io.quarkiverse.cxf.client.it.rtinit.Operands.<clinit>(Operands.java)
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
[INFO] [stdout]                         1.4s (4.8% of total time) in 26 GCs | Peak RSS: 4.61GB | CPU load: 11.88
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
[WARN] [stderr]         at java.lang.Class.forName0(Unknown Source)
[INFO] [stdout] ========================================================================================================================
[WARN] [stderr]         at java.lang.Class.forName(Class.java:467)
[INFO] [stdout] Failed generating 'quarkus-cxf-integration-test-client-2.0.0-SNAPSHOT-runner' after 29.2s.
[WARN] [stderr]         at io.quarkus.deployment.steps.JaxbProcessor$setupJaxbContextConfig1556898737.deploy_0(Unknown Source)
[WARN] [stderr]         at io.quarkus.deployment.steps.JaxbProcessor$setupJaxbContextConfig1556898737.deploy(Unknown Source)
[WARN] [stderr]         at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
[WARN] [stderr]         at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
```

See the first commit of this PR for a reproducer: https://github.com/quarkiverse/quarkus-cxf/pull/771/commits

I guess SOAP service methods having a runtime initialized argument will be a rather rare, but still possible case that we should support in Quarkus CXF. In the test the runtime init is forced via `quarkus.native.additional-build-args=--initialize-at-run-time=io.quarkiverse.cxf.client.it.rtinit.Operands`

In https://github.com/quarkusio/quarkus/pull/31666 we made the runtime validation of the default JAXBContext required only if the application actually uses the default JAXBContext - i.e. if there is at least one injection point for it. 

Clearly, if a the default JAXBContext would be used by the application, then this issue is expected.

But OTOH, I believe, that when the default JAXBContext is not required by the application, then the classes for it should not be loaded at build time. Fixing this seems to be quite easy and I am going to send a PR to see whether it really works for all existing JAXB tests.




### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

_No response_

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

_No response_

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

_No response_

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

_No response_

### Additional information

_No response_

Changed files:
extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java

diff --git a/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java b/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java
index 41ca49b5206..29255342e9a 100644
--- a/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java
+++ b/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java
@@ -314,14 +314,6 @@ FilteredJaxbClassesToBeBoundBuildItem filterBoundClasses(
         return builder.build();
     }
 
-    @BuildStep
-    @Record(ExecutionTime.STATIC_INIT)
-    void setupJaxbContextConfig(
-            FilteredJaxbClassesToBeBoundBuildItem filteredClassesToBeBound,
-            JaxbContextConfigRecorder jaxbContextConfig) {
-        jaxbContextConfig.addClassesToBeBound(filteredClassesToBeBound.getClasses());
-    }
-
     @BuildStep
     @Record(ExecutionTime.STATIC_INIT)
     void validateDefaultJaxbContext(
@@ -335,6 +327,7 @@ void validateDefaultJaxbContext(
             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()) {
                     /*