quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

JaxbProcessor should not register package-info to be bound to JaxbContext

Open isarantidis opened this issue 3 years ago • 11 comments

Describe the bug

Commit Allow to provide custom configuration for JAXB context , introduced changes to the JaxbProcessor. One of the changes results in the inclusion of package-infos to be bound to the JaxbContext

  for (AnnotationInstance xmlSchemaInstance : index.getAnnotations(XML_SCHEMA)) {
            if (xmlSchemaInstance.target().kind() == Kind.CLASS) {
                reflectiveClass.produce(
                        new ReflectiveClassBuildItem(false, false, xmlSchemaInstance.target().asClass().name().toString()));
                String className = xmlSchemaInstance.target().asClass().name().toString();

                reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, className));

                classesToBeBound.add(className);
            }
        }

Expected behavior

No response

Actual behavior

Including camel's extensions via quarkus-camel-bom results in exceptions such as the following:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 21 counts of IllegalAnnotationExceptions org.apache.camel.model.errorhandler.package-info is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at org.apache.camel.model.errorhandler.package-info org.apache.camel.model.config.package-info is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at org.apache.camel.model.config.package-info Two classes have the same XML type name "{http://camel.apache.org/schema/spring}packageInfo". Use @XmlType.name and @XmlType.namespace to assign different names to them. this problem is related to the following location: at org.apache.camel.model.errorhandler.package-info this problem is related to the following location: at org.apache.camel.model.config.package-info

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

openjdk version "11.0.14" 2022-01-18 OpenJDK Runtime Environment GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05) OpenJDK 64-Bit Server VM GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.11.1

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

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)

Additional information

No response

isarantidis avatar Jul 28 '22 13:07 isarantidis

/cc @gsmet

quarkus-bot[bot] avatar Jul 28 '22 13:07 quarkus-bot[bot]

/cc @geoand

gsmet avatar Jul 28 '22 13:07 gsmet

Interesting. I'll have a look tomorrow

geoand avatar Jul 28 '22 15:07 geoand

Hm... I really know much of anything about XML, so we'll have to let @Sgitario comment on why the change above was made.

geoand avatar Jul 29 '22 06:07 geoand

My impression is that package-info's need not be bound to the JaxbContext explicitly, but during building the context they are automatically scanned for annotations if they are in the same package as one of the classes to be bound.

isarantidis avatar Jul 29 '22 09:07 isarantidis

Yeah, I agree, but my point is what the change was made explicitly for some reason which I am not privy to. So best to wait for @Sgitario

geoand avatar Jul 29 '22 09:07 geoand

My impression is that package-info's need not be bound to the JaxbContext explicitly, but during building the context they are automatically scanned for annotations if they are in the same package as one of the classes to be bound.

That piece of code searchs for @XmlSchema annotation, that can be used only in package-info, so I think this was done for a reason and not incidentally.

masini avatar Aug 03 '22 09:08 masini

Yeah, that's my problem. I don't know why it was done unfortunately :(

geoand avatar Aug 03 '22 09:08 geoand

The intention was to register the JAXB annotations declared into the package info, not the package info java class itself. However, I don't see how your package info was added as part of the classes to be bounded into the JAXB Context. Can you share a reproducer so I could quickly look at?

Sgitario avatar Aug 08 '22 06:08 Sgitario

I have created a repository that reproduces both errors https://github.com/isarantidis/PackageInfoQuarkusError

  • First the inclusion of a package-info class results in the error package-info is an interface, and JAXB can't handle interfaces.
  • Second the addition of any camel quarkus library that results in camel-core-model artifact to be included, results in the error Two classes have the same XML type name "http://camel.apache.org/schema/spring}packageInfo". Use @XmlType.name and @XmlType.namespace to assign different names to them. e.g.
<dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-bean</artifactId>
</dependency>

isarantidis avatar Aug 09 '22 18:08 isarantidis

I have created a repository that reproduces both errors https://github.com/isarantidis/PackageInfoQuarkusError

  • First the inclusion of a package-info class results in the error package-info is an interface, and JAXB can't handle interfaces.
  • Second the addition of any camel quarkus library that results in camel-core-model artifact to be included, results in the error Two classes have the same XML type name "http://camel.apache.org/schema/spring}packageInfo". Use @XmlType.name and @XmlType.namespace to assign different names to them. e.g.
<dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-bean</artifactId>
</dependency>

Many thanks. I tried to build the reproducer and it was not failing for me. Anyway, I added a package-info.java in the extension and it was indeed failing. I've fixed it as part of this pull request: https://github.com/quarkusio/quarkus/pull/27218

Sgitario avatar Aug 10 '22 05:08 Sgitario

Apologies, apparently i forgot to mention i was testing the reproducer via launching the application and hitting the endpoint http://localhost:7070/account with a POST request, instead of having written a test. In any case, I tested the fix and the error is gone :)

isarantidis avatar Aug 10 '22 19:08 isarantidis