Recorder does not fire in native executable

65 Views Asked by At

In our setup, we perform some STATIC-INIT build steps including adding all resource paths to a list in an object. We use a Recorder for this, because the object cannot be accessed during the static init phase. In JVM mode, we see that the list does indeed contain all resource paths. However, this is not the case in Native mode. The list remains empty, even though the build logs show that we iterated over the resources and added them to the list.

This is what our setup looks like:

First: The file that is accessible at runtime and contains all resource paths.

@ApplicationScoped
public class ServiceResourcesList {

    private List<String> resources;

    public ServiceResourcesList() {
        resources = new ArrayList<>();
    }

    public void addResource(String resource) {
        this.resources.add(resource);
    }

    public List<String> getResources() {
        return resources;
    }

    public List<String> getResources(Predicate<String> filter) {
        return resources.stream().filter(filter).collect(Collectors.toList());
    }
}

The recorder, which returns a BeanContainerListener:

@Recorder
public class ServiceResourcesListRecorder {

    public BeanContainerListener addResourceToList(String resource) {
        return beanContainer -> {
            ServiceResourcesList producer = beanContainer.instance(ServiceResourcesList.class);
            producer.addResource(resource);
        };
    }
}

And finally the (simplified) buildstep. Note that we use a BuildProducer which should make sure that the objects have been registered already before applying the Recorder methods.

@BuildStep
@Record(STATIC_INIT)
void createResourceList(final BuildProducer<BeanContainerListenerBuildItem> containerListenerProducer, ServiceResourcesListRecorder recorder) {

    // Some code to get the resource paths, but this could be anything
    // ...

    for (String resourcePath: resourcePaths) {
        LOGGER.info(resourcePath + " added to recorder");
        containerListenerProducer.produce(new BeanContainerListenerBuildItem(recorder.addResourceToList(resourcePath)));
    }
}

Am I doing something wrong? Are recorders not meant to be used for native executables? Should I add RegisterForReflection somewhere?

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

We solved this problem by using RUNTIME-INIT and static methods instead.