javajava-9

Java, IllegalAccessorError: superclass access check failed


I've been working on a little project of my own in Java, and recently, I compiled it and received this error:

Exception in thread "main" java.lang.IllegalAccessError: superclass access check failed: class kröw.zeale.v1.program.core.DataManager$ConstructList (in unnamed module @0x4563e9ab) cannot access class com.sun.javafx.collections.ObservableListWrapper (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @0x4563e9ab

Background:

So, I currently have three different classes, all in the same package. My hierarchy is as follows:

• Kröw
• DataManager
   ♦ ConstructList

In previous versions of my program, my hierarchy was like this:

• Kröw
   ♦ DataManager
      - ConstructList

In both cases, ConstructList extended com.sun.javafx.collections.ObservableListWrapper<Construct>. (I don't think that the class Construct is necessary here and I'd rather not show it, but I can if needed.)

Anyways, right now, my IDE can run the application as expected, however, when I export it, the above exception is given to me.

Full Stack Trace:

Exception in thread "main" java.lang.IllegalAccessError: superclass access check failed: class kröw.zeale.v1.program.core.DataManager$ConstructList (in unnamed module @0x4563e9ab) cannot access class com.sun.javafx.collections.ObservableListWrapper (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @0x4563e9ab
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
        at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        at kröw.zeale.v1.program.core.DataManager.<init>(DataManager.java:22)
        at kröw.zeale.v1.program.core.DataManager.getDataManager(DataManager.java:63)
        at kröw.zeale.v1.program.core.Kröw.<clinit>(Kröw.java:23)

Part of class Kröw that is mentioned in the error:

private static final DataManager DATA_MANAGER = DataManager.getDataManager(); // line 23

Parts of class DataManager that are mentioned in the error:

static DataManager getDataManager() { // line 66
    return new DataManager();
}

and

public final ConstructList constructs = new ConstructList();  // line 22

Class ConstructList:

public class ConstructList extends ObservableListWrapper<Construct> { // line 209

    private ConstructList() {
        super(new ArrayList<>()); // line 212
    }

   public LinkedList<Construct> getDeadConstructs() {
      ...
   }

   public LinkedList<Construct> getLivingConstructs() {
      ...
   }
}

Now, I have looked at the resources that I could find, such as IllegalAccessError SO Question

(Notice how this said: "tried to access method" instead of "superclass access check failed")

The accepted answer to that solution was to check if anything is different between the compiled jar file and my source code, so I tried that and found some minor differences. Here are the changed lines of code from my decompiled jar file. (Decompiled using JD-GUI)

Class DataManager:

public final ConstructList constructs = new ConstructList(null);

Used to be:

public final ConstructList constructs = new ConstructList();

Class ConstructList:

private ConstructList() {
  super();
}

Used to be:

private ConstructList() {
   super(new ArrayList<>());
}

Now, in the decompiled code, the ConstructList() constructor does not have any parameters, and I see it being invoked with null being passed in, which looks like an error to me, but I'm not sure if it is the cause of my exception and I haven't been able to find anything via the internet, which is why I came here.

On another note, the decompiled code I've given was created by my IDE, using its export function. I would like to see if the null argument with my constructor is the problem, but I do not know how to compile my code in a different way to reflect that. If someone knows how I can change the exported code I am getting, please inform me.

Anyways, what I want to know is what part of my code this exception is caused by, and how I can fix it.


Solution

  • It turns out you were compiling with Java 9 which utilizes the JDK's new module system. There is probably a valid way to fix your problem by implementing modules, however another solution is to simply compile with Java 8!