Skip to content

ActiveMQ Artemis Connection Factory creation fails in native image #42414

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
krezovic opened this issue Sep 22, 2024 · 3 comments
Closed

ActiveMQ Artemis Connection Factory creation fails in native image #42414

krezovic opened this issue Sep 22, 2024 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@krezovic
Copy link

See reproducer: https://github.com/krezovic/artemis-native-demo

./mvnw clean package -P native
./mvnw native:compile-no-fork
target/artemis-native-demo

Results in

Caused by: java.lang.NoSuchMethodException: org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(java.lang.String)
        at java.base@21.0.4/java.lang.Class.checkMethod(DynamicHub.java:1078)
        at java.base@21.0.4/java.lang.Class.getConstructor0(DynamicHub.java:1241)
        at java.base@21.0.4/java.lang.Class.getConstructor(DynamicHub.java:2442)
        at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.newNativeConnectionFactory(ArtemisConnectionFactoryFactory.java:146)
        at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.createNativeConnectionFactory(ArtemisConnectionFactoryFactory.java:134)
        at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.doCreateConnectionFactory(ArtemisConnectionFactoryFactory.java:95)
        at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.createConnectionFactory(ArtemisConnectionFactoryFactory.java:67)

Short guess, reflection hints are missing for factory creation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 22, 2024
@philwebb
Copy link
Member

I think we either need a hint or we need to change ArtemisConnectionFactoryFactory.createConnectionFactory(...) to take a Function<String,ActiveMQConnectionFactory>.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 23, 2024
@philwebb philwebb added this to the 3.2.x milestone Sep 23, 2024
@wilkinsona wilkinsona self-assigned this Sep 23, 2024
@wilkinsona
Copy link
Member

wilkinsona commented Sep 23, 2024

We can (and will) fix the problem caused by Boot's use of reflection, but please note that you'll then hit a problem within Artemis' code and its use of bean utils:

Caused by: java.lang.IllegalStateException: java.lang.ExceptionInInitializerError
	at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:239)
	at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.newNativeConnectionFactory(ArtemisConnectionFactoryFactory.java:147)
	at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.createNativeConnectionFactory(ArtemisConnectionFactoryFactory.java:135)
	at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.doCreateConnectionFactory(ArtemisConnectionFactoryFactory.java:97)
	at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.createConnectionFactory(ArtemisConnectionFactoryFactory.java:68)
	... 140 more
Caused by: java.lang.ExceptionInInitializerError
	at org.apache.activemq.artemis.uri.schema.connector.TCPTransportConfigurationSchema.getTransportConfigurations(TCPTransportConfigurationSchema.java:65)
	at org.apache.activemq.artemis.uri.schema.serverLocator.TCPServerLocatorSchema.internalNewObject(TCPServerLocatorSchema.java:42)
	at org.apache.activemq.artemis.uri.schema.serverLocator.TCPServerLocatorSchema.internalNewObject(TCPServerLocatorSchema.java:33)
	at org.apache.activemq.artemis.utils.uri.URISchema.newObject(URISchema.java:84)
	at org.apache.activemq.artemis.utils.uri.URISchema.newObject(URISchema.java:28)
	at org.apache.activemq.artemis.utils.uri.URIFactory.newObject(URIFactory.java:59)
	at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.newLocator(ServerLocatorImpl.java:360)
	at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.setBrokerURL(ActiveMQConnectionFactory.java:257)
	at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:237)
	... 144 more
Caused by: java.lang.IllegalArgumentException: Class java.util.Date[] is instantiated reflectively but was never registered.Register the class by adding "unsafeAllocated" for the class in reflect-config.json.
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets.arrayHubErrorStub(SubstrateAllocationSnippets.java:351)
	at org.apache.commons.beanutils.ConvertUtilsBean.registerArrayConverter(ConvertUtilsBean.java:796)
	at org.apache.commons.beanutils.ConvertUtilsBean.registerArrays(ConvertUtilsBean.java:774)
	at org.apache.commons.beanutils.ConvertUtilsBean.deregister(ConvertUtilsBean.java:603)
	at org.apache.commons.beanutils.ConvertUtilsBean.<init>(ConvertUtilsBean.java:161)
	at org.apache.commons.beanutils.BeanUtilsBean.<init>(BeanUtilsBean.java:113)
	at org.apache.activemq.artemis.utils.uri.BeanSupport.<clinit>(BeanSupport.java:37)
	... 153 more

This will have to be addressed in one of Artemis, some reachability metadata, or some reflection hints of your own.

@krezovic
Copy link
Author

This seems to be the first issue on Google when searching for Artemis, Spring and native-image so I'll just leave a comment that I have updated to latest snapshot of spring-boot 3.4, generated metadata for artemis using native agent and the application now works as expected.

The changes were added as a separate commit in the repo provided in the original comment.

Thanks for the prompt fix from spring boot side.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants