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

Remove reflection in PropertyFactory so that GraalVM native-image does not need a hint. #1802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flx5
Copy link

@flx5 flx5 commented Jun 9, 2024

Hello,
recently I've experimented with GraalVM and native images.

However the Jaxb implementation resulted in an exception at runtime:

org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method public org.glassfish.jaxb.runtime.v2.runtime.property.SingleElementNodeProperty(org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl,org.glassfish.jaxb.runtime.v2.model.runtime.RuntimeElementPropertyInfo) without it being registered for runtime reflection. Add it to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils.forQueriedOnlyExecutable(MissingReflectionRegistrationUtils.java:97) ~[na:na]
at java.base@17.0.11/java.lang.reflect.Constructor.acquireConstructorAccessor(Constructor.java:74) ~[com.example.producingwebservice.ProducingWebServiceApplication:na]
at java.base@17.0.11/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:496) ~[com.example.producingwebservice.ProducingWebServiceApplication:na]
at java.base@17.0.11/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[com.example.producingwebservice.ProducingWebServiceApplication:na]
at org.glassfish.jaxb.runtime.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:94) ~[na:na]
at org.glassfish.jaxb.runtime.v2.runtime.ClassBeanInfoImpl.(ClassBeanInfoImpl.java:148) ~[na:na]
at org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:464) ~[com.example.producingwebservice.ProducingWebServiceApplication:4.0.4 - 75b0b97]
at org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:283) ~[com.example.producingwebservice.ProducingWebServiceApplication:4.0.4 - 75b0b97]
at org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1115) ~[na:na]
at org.glassfish.jaxb.runtime.v2.ContextFactory.createContext(ContextFactory.java:144) ~[com.example.producingwebservice.ProducingWebServiceApplication:4.0.4 - 75b0b97]
at org.glassfish.jaxb.runtime.v2.JAXBContextFactory.createContext(JAXBContextFactory.java:44) ~[com.example.producingwebservice.ProducingWebServiceApplication:4.0.4 - 75b0b97]
at jakarta.xml.bind.ContextFinder.find(ContextFinder.java:373) ~[na:na]
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:605) ~[com.example.producingwebservice.ProducingWebServiceApplication:4.0.1]
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:546) ~[com.example.producingwebservice.ProducingWebServiceApplication:4.0.1]
at org.springframework.ws.server.endpoint.adapter.method.jaxb.AbstractJaxb2PayloadMethodProcessor.getJaxbContext(AbstractJaxb2PayloadMethodProcessor.java:224) ~[com.example.producingwebservice.ProducingWebServiceApplication:na]

Three ideas to resolve this issue:

  1. Add reflection hints
  2. Replace reflection with functional programming (BiFunction instead of Constructor)
  3. Move property creation into RuntimePropertyInfo

In this PR I've implemented the third option. However I also have the second option available (See https://github.com/flx5/jaxb-ri/tree/feature/functional).

Signed-off-by: flx5 <1330854+flx5@users.noreply.github.com>
@flx5 flx5 force-pushed the feature/refactor-property-factory branch from 168bf0d to bca8832 Compare June 9, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant