Error when created a SharedService in a multi-sandboxed Kernel

Hello MicroEJ’s team :waving_hand:

I’m facing an issue when launching my Kernel with a SharedService for multi-sandboxed applications.

My environment:

  • my-kernel
  • my-kernel-application
  • vee-port RTX1170

Here is my code in Kernel side:

public static void main(String[] args) {
    String kernelName = Kernel.getInstance().getName();
    LOGGER.info(kernelName + " Hello World!");

    Timer myTimer = new Timer();
    ServiceRegistryKF serviceRegistryKF = (ServiceRegistryKF) ServiceFactory.getServiceRegistry();
    serviceRegistryKF.register(Timer.class, myTimer, false);
}

Here is my code in the Application side:

public static void main(String[] args) {
    Timer timer = ServiceFactory.getService(Timer.class);
    if(timer != null) {
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                LOGGER.info("Hello from TimerTask !");
            }
        };
        timer.schedule(timerTask, 0, 500);
    }
}

My Scenario:

  • Kernel: gradle runOnDevice
  • Application: gradle buildExecutable
  • Copy/Paste application.fo in my microSD card
  • Reboot my RT1170 board
  • BUG I see an error

Here is my readable error (after running gradle stackTraceReader):

java.lang.ExceptionInInitializerError: java.lang.IllegalArgumentException
	at java.lang.System.getStackTrace(Unknown Source)
	at java.lang.Throwable.fillInStackTrace(Throwable.java:109)
	at java.lang.Throwable.<init>(Throwable.java:57)
	at java.lang.Error.<init>(Error.java:26)
	at java.lang.LinkageError.<init>(LinkageError.java:26)
	at java.lang.ExceptionInInitializerError.<init>(ExceptionInInitializerError.java:22)
	at java.lang.Thread.clinitWrapper(Thread.java:491)
	at java.lang.Thread.callWrapper(Thread.java:450)
Caused by: java.lang.IllegalArgumentException
	at java.lang.System.getStackTrace(Unknown Source)
	at java.lang.Throwable.fillInStackTrace(Throwable.java:109)
	at java.lang.Throwable.<init>(Throwable.java:38)
	at ej.property.SharedPropertyFactory.getSharedPropertyRegistryInstance(SharedPropertyFactory.java:25)
	at ej.property.SharedPropertyFactory.<clinit>(SharedPropertyFactory.java:16)
	at java.lang.Thread.execClinit(Unknown Source)
	at java.lang.Thread.clinitWrapper(Thread.java:484)

It’s look like the problem is not coming from my code because I don’t find an error on one of my file.

Could you help me ?

Thank you :folded_hands:

Hi Emma,

Good catch, that’s a known issue on our side that we will fix in the next version of our kf-util library.

A quick workaround is to define the following property in a kernel.types.list file in your kernel resources:

ej.property.SharedPropertyRegistry

By default, your kernel binary does not include the ej.property.SharedPropertyRegistry type, yet the Service API you are using depends on it. A common cause of this is the soar.generate.classnames property being disabled or not configured in your kernel.

Defining this type is the kernel.types.list forces the type to be embedded during the build process. See the Types documentation for more information.

Regards,

Alex

1 Like

Thank you Alex it works ! :tada: