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

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

Closed
isarantidis opened this issue Jul 28, 2022 · 12 comments · Fixed by #27218
Closed

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

isarantidis opened this issue Jul 28, 2022 · 12 comments · Fixed by #27218
Labels
area/jaxb kind/bug Something isn't working
Milestone

Comments

@isarantidis
Copy link

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 isarantidis added the kind/bug Something isn't working label Jul 28, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 28, 2022

/cc @gsmet

@gsmet
Copy link
Member

gsmet commented Jul 28, 2022

/cc @geoand

@geoand
Copy link
Contributor

geoand commented Jul 28, 2022

Interesting. I'll have a look tomorrow

@geoand
Copy link
Contributor

geoand commented Jul 29, 2022

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

@isarantidis
Copy link
Author

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.

@geoand
Copy link
Contributor

geoand commented Jul 29, 2022

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

@masini
Copy link
Contributor

masini commented Aug 3, 2022

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.

@geoand
Copy link
Contributor

geoand commented Aug 3, 2022

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

@Sgitario
Copy link
Contributor

Sgitario commented Aug 8, 2022

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?

@isarantidis
Copy link
Author

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>

Sgitario added a commit to Sgitario/quarkus that referenced this issue Aug 10, 2022
The classes annotated with @XmlSchema within package-info results into errors because the package-info is not a class. 

These changes fix this issue by adding a package-info.java class and not bounding this class to the JAXBContext.

Fix quarkusio#27003
@Sgitario
Copy link
Contributor

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: #27218

@isarantidis
Copy link
Author

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 :)

@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Aug 11, 2022
@gsmet gsmet modified the milestones: 2.12.0.CR1, 2.11.3.Final Aug 23, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 23, 2022
The classes annotated with @XmlSchema within package-info results into errors because the package-info is not a class.

These changes fix this issue by adding a package-info.java class and not bounding this class to the JAXBContext.

Fix quarkusio#27003

(cherry picked from commit 89499a7)
miador pushed a commit to miador/quarkus that referenced this issue Sep 6, 2022
The classes annotated with @XmlSchema within package-info results into errors because the package-info is not a class. 

These changes fix this issue by adding a package-info.java class and not bounding this class to the JAXBContext.

Fix quarkusio#27003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jaxb kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants