error-handlingcodenameoneillegalaccessexception

Codename one - Form.initLaf throws random "Illegal Access" errors


in my app, I get "IllegalAccess" errors, at seemingly random places and times. The only thing in common is the stack trace:

java.lang.IllegalAccessError: class sun.reflect.GeneratedConstructorAccessor3 cannot access its superclass sun.reflect.ConstructorAccessorImpl
at sun.misc.Unsafe.defineClass(Native Method)
at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:92)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:55)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
**at com.codename1.ui.Form.initLaf(Form.java:969)**
at com.codename1.ui.Dialog.initLaf(Dialog.java:499)
at com.codename1.ui.Component.<init>(Component.java:687)
at com.codename1.ui.Container.<init>(Container.java:187)
at com.codename1.ui.Container.<init>(Container.java:199)
at com.codename1.ui.Form.<init>(Form.java:181)
at com.codename1.ui.Form.<init>(Form.java:172)
at com.codename1.ui.Dialog.<init>(Dialog.java:288)
at com.codename1.ui.Dialog.<init>(Dialog.java:275)
at com.codename1.ui.Dialog.<init>(Dialog.java:248)
at com.codename1.ui.Dialog.show(Dialog.java:994)
at com.codename1.ui.Dialog.show(Dialog.java:793)
at com.codename1.ui.Dialog.show(Dialog.java:746)
at com.codename1.ui.Dialog.show(Dialog.java:711)
at com.codename1.ui.Dialog.show(Dialog.java:652)
at com.codename1.ui.Dialog.show(Dialog.java:807)
at com.codename1.ui.Display.mainEDTLoop(Display.java:983)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

The line marked with ** .. ** is my annotation as this is the method of the Form class that throws the error. Either when I open a new form, a dialog (which inherits from Form) or just anything that involves creating a new Form, this issue occurs, at random.

I have no idea how to debug this, as it seems that it is not my code that is causing the issue.

Any tips for debugging or even solving the issue?

EDIT

the error is not only limited to the creation of forms, but can also occur when internalizing objects. See stacktrace:

<same as above stacktrace after Class.newinstance>
at java.lang.Class.newInstance(Class.java:442)
at com.codename1.io.Util.readObject(Util.java:690)
at com.codename1.io.Util.readObject(Util.java:668)
at com.lequi.ep.dtos.ChatDTO.internalize(ChatDTO.java:47)
at com.codename1.io.Util.readObject(Util.java:693)

EDIT 2

with a lot more testing this issue, I found a single pattern so far. no matter which form or dialog I create, it depends on the number of times I instantiate them. At exactly the 13th time I want to instantiate a form (no matter which screen), this error pops up. I dont have to do anything, just opening the screen and going back. Relevant code snipped with which the error can be reproduced:

// main form activity 
<omitted for brevity>
chatButton.addActionListener(e -> {
    new ChatScreen(this).show();
});

public ChatScreen(Form origin) {
    super("Chat", new BorderLayout());
    setUIID("ChatHistory");

    getToolbar().setBackCommand("", e -> {
        origin.showBack();
    });
    <omitted for brevity>
 }

Solution

  • After setting up a second dev environment, importing my git project one to one, without any issues and also noting that this error does not happen on the mobile device itself, the issue can be limited to my specific environment.

    I still dont know why this occurs, but the impact is neglectable.