How to add a bean to the Jandex index in an extension deployment module

2,216 views
Skip to first unread message

Loïc MATHIEU

unread,
Jul 22, 2019, 9:28:15 AM7/22/19
to Quarkus Development mailing list
Hello,

I'm struggle with the following error when creating my Panache Mongo extension :
15:11:13,696 WARN  [io.qua.dep.ste.ReflectiveHierarchyStep] Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
- org.bson.types.ObjectId
Consider adding them to the index either by creating a Jandex index for your dependency via the Maven plugin, an empty META-INF/beans.xml or quarkus.index-dependency properties.");.


I try to register the ObjectId class in a lot of different way in the Deployment Processor but none solves the issue:

@BuildStep
AdditionalBeanBuildItem registerAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> beans) {
beans.produce(AdditionalBeanBuildItem.unremovableOf(ObjectId.class));

AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder();
builder.addBeanClass(ObjectId.class);
return builder.build();
}

@BuildStep
BeanDefiningAnnotationBuildItem registerX() {
return new BeanDefiningAnnotationBuildItem(DOTNAME_BSON_ID);
}
I'm sure I miss something somewhere ... ObjectId is used as a field from an class that is enhanced by the deployment processor so I thought that Jandex will knows it.

Regards,

Loïc

Martin Kouba

unread,
Jul 22, 2019, 9:38:55 AM7/22/19
to loik...@gmail.com, Quarkus Development mailing list
Hi Loïc,

This warning comes from the ReflectiveHierarchyStep which only works
with the CombinedIndexBuildItem which only considers the application
archive indexes. In other words, additional beans will not help here
(these are only added to the bean archive used by CDI). See
https://stackoverflow.com/a/55513723/2654154 for more info how to index
the dependency.

Martin

Dne 22. 07. 19 v 15:28 Loïc MATHIEU napsal(a):
> Hello,
>
> I'm struggle with the following error when creating my Panache Mongo
> extension :
> 15:11:13,696 WARN  [io.qua.dep.ste.ReflectiveHierarchyStep] Unable to
> properly register the hierarchy of the following classes for reflection
> as they are not in the Jandex index:
> - org.bson.types.ObjectId
> Consider adding them to the index either by creating a Jandex index for
> your dependency via the Maven plugin, an empty META-INF/beans.xml or
> quarkus.index-dependency properties.");.
>
> I try to register the ObjectId class in a lot of different way in the
> Deployment Processor but none solves the issue:
>
> @BuildStep
> AdditionalBeanBuildItemregisterAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> beans) {
> beans.produce(AdditionalBeanBuildItem.unremovableOf(ObjectId.class));
>
> AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder();
> builder.addBeanClass(ObjectId.class);
> return builder.build();
> }
>
> @BuildStep
> BeanDefiningAnnotationBuildItemregisterX() {
> return new BeanDefiningAnnotationBuildItem(DOTNAME_BSON_ID);
> }
>
> I'm sure I miss something somewhere ... ObjectId is used as a field from
> an class that is enhanced by the deployment processor so I thought that
> Jandex will knows it.
>
> Regards,
>
> Loïc
>
> --
> You received this message because you are subscribed to the Google
> Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/quarkus-dev/CAJLxjVHEvzppK3gn5UysBhT%2BYw1W_n6RNYSFwFsRcTTLjX9xWw%40mail.gmail.com
> <https://groups.google.com/d/msgid/quarkus-dev/CAJLxjVHEvzppK3gn5UysBhT%2BYw1W_n6RNYSFwFsRcTTLjX9xWw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic

Loïc MATHIEU

unread,
Jul 22, 2019, 10:53:23 AM7/22/19
to Martin Kouba, Quarkus Development mailing list
Thanks for the explaination Martin, I already tested the Jandex plugin and I think that somethig else is happening.

In fact, the class is used in a Quarkus Extension, so the plugin should not be necessary.

This is the full stacktrace, the cause is strange (a linkage error from Arc)
16:50:54,990 WARN  [io.qua.dep.ste.ReflectiveHierarchyStep] Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:

- org.bson.types.ObjectId
Consider adding them to the index either by creating a Jandex index for your dependency via the Maven plugin, an empty META-INF/beans.xml or quarkus.index-dependency properties.");.
16:50:55,186 ERROR [io.qua.dev.DevModeMain] Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:141)
at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:171)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:89)
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at io.quarkus.builder.Execution.run(Execution.java:108)
at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:121)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:122)
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:107)
... 2 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.jboss.classfilewriter.DefaultClassFactory.defineClass(DefaultClassFactory.java:107)
at org.jboss.classfilewriter.ClassFile.defineInternal(ClassFile.java:299)
at org.jboss.classfilewriter.ClassFile.define(ClassFile.java:277)
at org.jboss.invocation.proxy.AbstractClassFactory.defineClass(AbstractClassFactory.java:200)
at org.jboss.invocation.proxy.AbstractClassFactory.newInstance(AbstractClassFactory.java:263)
at org.jboss.invocation.proxy.ProxyFactory.newInstance(ProxyFactory.java:270)
at io.quarkus.deployment.recording.BytecodeRecorderImpl.getProxyInstance(BytecodeRecorderImpl.java:262)
at io.quarkus.deployment.recording.BytecodeRecorderImpl.access$200(BytecodeRecorderImpl.java:81)
at io.quarkus.deployment.recording.BytecodeRecorderImpl$1.invoke(BytecodeRecorderImpl.java:228)
at io.quarkus.deployment.recording.BytecodeRecorderImpl$$RecordingProxyProxy16.getContainer(Unknown Source)
at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:311)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.quarkus.deployment.ExtensionLoader$1.execute(ExtensionLoader.java:508)
at io.quarkus.builder.BuildContext.run(BuildContext.java:415)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2011)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1538)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1429)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.classfilewriter.DefaultClassFactory.defineClass(DefaultClassFactory.java:103)
... 22 more
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of io/quarkus/runner/RuntimeClassLoader) previously initiated loading for a different type with name "io/quarkus/arc/ArcContainer"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at io.quarkus.runner.RuntimeClassLoader.findClass(RuntimeClassLoader.java:217)
at io.quarkus.runner.RuntimeClassLoader.loadClass(RuntimeClassLoader.java:163)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
... 27 more

Loïc MATHIEU

unread,
Jul 22, 2019, 11:29:05 AM7/22/19
to Martin Kouba, Quarkus Development mailing list
I'm pretty sure it has something to do around Arc as when I add the following properties:
quarkus.index-dependency.mongodb.group-id=org.mongodb
quarkus.index-dependency.mongodb.artifact-id=mongo-java-driver
I no longer have the Jandex WARNING but still the Arc exception. And when I build the app the exception disapear.
This has something to do with dev mode.

I build Quarkus from master, maybe master is un-stable.

Guillaume Smet

unread,
Jul 22, 2019, 12:04:17 PM7/22/19
to Loïc MATHIEU, Martin Kouba, Quarkus Development mailing list
On Mon, Jul 22, 2019 at 5:29 PM Loïc MATHIEU <loik...@gmail.com> wrote:
I build Quarkus from master, maybe master is un-stable.

It shouldn't be. Not on purpose. So if you have a specific issue, we need to fix it before the next release.

--
Guillaume

Martin Kouba

unread,
Jul 23, 2019, 2:11:40 AM7/23/19
to Loïc MATHIEU, Quarkus Development mailing list

Dne 22. 07. 19 v 17:28 Loïc MATHIEU napsal(a):
> I'm pretty sure it has something to do around Arc as when I add the
> following properties:
>
> quarkus.index-dependency.mongodb.group-id=org.mongodb
> quarkus.index-dependency.mongodb.artifact-id=mongo-java-driver
>
> I no longer have the Jandex WARNING but still the Arc exception. And
> when I build the app the exception disapear.
> This has something to do with dev mode.

I think we really need a reproducer. The LinkageError scares me a little
bit...

>
> I build Quarkus from master, maybe master is un-stable.
>
> Le lun. 22 juil. 2019 à 16:53, Loïc MATHIEU <loik...@gmail.com
> <mailto:loik...@gmail.com>> a écrit :
> <mailto:mko...@redhat.com>> a écrit :
> <mailto:quarkus-dev%2Bunsu...@googlegroups.com>
> > <mailto:quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev%2Bunsu...@googlegroups.com>>.

Loïc MATHIEU

unread,
Jul 23, 2019, 3:54:32 AM7/23/19
to Martin Kouba, Quarkus Development mailing list
You should be able to reproduce the error using my branch of Quarkus: https://github.com/loicmathieu/quarkus/tree/features/mongo_panache
- Build Quakus
- Launch the mongodb-panache integration test https://github.com/loicmathieu/quarkus/tree/features/mongo_panache/integration-tests/mongodb-panache with `mvn clean compile quarkus:dev`

I know it's not very convenient but I didn't have the time to make an eaisier reproducer.

Martin Kouba

unread,
Jul 23, 2019, 10:46:20 AM7/23/19
to Loïc MATHIEU, Quarkus Development mailing list
I get "Could not find artifact
io.quarkus:quarkus-mongo:jar:999-SNAPSHOT" when building your branch.
Should it be "io.quarkus:quarkus-mongo-client" instead?

Anyway I was able to reproduce the issue and now I'm trying to identify
the problem...

Martin

Dne 23. 07. 19 v 9:54 Loïc MATHIEU napsal(a):
> You should be able to reproduce the error using my branch of Quarkus:
> https://github.com/loicmathieu/quarkus/tree/features/mongo_panache
> - Build Quakus
> - Launch the mongodb-panache integration test
> https://github.com/loicmathieu/quarkus/tree/features/mongo_panache/integration-tests/mongodb-panache with
> `mvn clean compile quarkus:dev`
>
> I know it's not very convenient but I didn't have the time to make an
> eaisier reproducer.
>
> Le mar. 23 juil. 2019 à 08:11, Martin Kouba <mko...@redhat.com
> <mailto:mko...@redhat.com>> a écrit :
>
>
> Dne 22. 07. 19 v 17:28 Loïc MATHIEU napsal(a):
> > I'm pretty sure it has something to do around Arc as when I add the
> > following properties:
> >
> > quarkus.index-dependency.mongodb.group-id=org.mongodb
> > quarkus.index-dependency.mongodb.artifact-id=mongo-java-driver
> >
> > I no longer have the Jandex WARNING but still the Arc exception. And
> > when I build the app the exception disapear.
> > This has something to do with dev mode.
>
> I think we really need a reproducer. The LinkageError scares me a
> little
> bit...
>
> >
> > I build Quarkus from master, maybe master is un-stable.
> >
> > Le lun. 22 juil. 2019 à 16:53, Loïc MATHIEU <loik...@gmail.com
> <mailto:loik...@gmail.com>
> > <mailto:loik...@gmail.com <mailto:loik...@gmail.com>>> a écrit :
> >     <mailto:mko...@redhat.com <mailto:mko...@redhat.com>>> a écrit :
> >         <mailto:quarkus-dev%2Bunsu...@googlegroups.com
> <mailto:quarkus-dev%252Buns...@googlegroups.com>>
> >          > <mailto:quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev%2Bunsu...@googlegroups.com>
> >         <mailto:quarkus-dev%2Bunsu...@googlegroups.com
> <mailto:quarkus-dev%252Buns...@googlegroups.com>>>.

Martin Kouba

unread,
Jul 23, 2019, 11:16:15 AM7/23/19
to Loïc MATHIEU, Quarkus Development mailing list
So the dev mode only works if you specify the "noDeps" property:

mvn compile quarkus:dev -DnoDeps

If not specified other module dependencies in the project should trigger
hot-reload too. This is not the case for quarkus project repo.

Martin

Dne 23. 07. 19 v 16:46 Martin Kouba napsal(a):

Loïc MATHIEU

unread,
Jul 23, 2019, 11:24:42 AM7/23/19
to Martin Kouba, Quarkus Development mailing list
Thanks Martin, 

My extension depends on the mongodb-client extension (there should a wrong commit done, that's why you have the artifact not found error ...).
It's common that an extension depends on another one, I don't understand why you said that "This is not the case for quarkus project repo." ?
Maybe I'm doing something wrong?

Regards,

Loïc

Martin Kouba

unread,
Jul 24, 2019, 1:03:09 AM7/24/19
to Loïc MATHIEU, Quarkus Development mailing list
Dne 23. 07. 19 v 17:24 Loïc MATHIEU napsal(a):
> Thanks Martin,
>
> My extension depends on the mongodb-client extension (there should a
> wrong commit done, that's why you have the artifact not found error ...).
> It's common that an extension depends on another one, I don't understand
> why you said that "This is not the case for quarkus project repo." ?

I meant that we don't want this feature (hot-reload for other modules in
a multi-module maven project) enabled inside the quarkus maven project
because it contains other modules that are extensions. This will not
work. This feauture is useful for multi-module application project.

> Maybe I'm doing something wrong?
>
> Regards,
>
> Loïc
>
> Le mar. 23 juil. 2019 à 17:16, Martin Kouba <mko...@redhat.com
> <mailto:mko...@redhat.com>> a écrit :
> >> <mailto:mko...@redhat.com <mailto:mko...@redhat.com>>> a écrit :
> >>
> >>
>  <mailto:quarkus-dev%2Bunsu...@googlegroups.com
> <mailto:quarkus-dev%252Buns...@googlegroups.com>
> >>     <mailto:quarkus-dev%252Buns...@googlegroups.com
> <mailto:quarkus-dev%25252Bun...@googlegroups.com>>>
> >>     <mailto:quarkus-dev%252Buns...@googlegroups.com
> <mailto:quarkus-dev%25252Bun...@googlegroups.com>>>>.
Reply all
Reply to author
Forward
0 new messages