Unable to load processing.core.ThinkDifferent methods

EDIT - it was the java version (15 vs 1.8). I was aware of Processing’s java version restrictions (1.8 but w/o lambdas, etc.) but didn’t think it would affect being able to inspect the ThinkDifferent class. In any case, hopefully this will help others who may encounter an issue similar to this…

I have a strange error situation at startup. First, I’m developing on MAC OS X, using IntelliJ for my IDE, OpenJDK 15, and using processing ‘core.jar’ (V3.3.7). Within the main() of my application’s main class I immediately invoke PApplet.main(…) with my class name. During this invocation I get a NoClassDefFoundError exception (see stacktrace). In GitHub I looked through the Processing PApplet source and seem to have narrowed things down to where it attempts to get the “init” method of the processing.core.ThinkDifferent class via reflection. My classpath looks correct and I confirmed that the ThinkDifferent class is in fact contained within the core-3.3.7.jar I’m using. So to experiment a bit I replaced my call to PApplet.main() with some code that simply tries to load in the ThinkDifferent class and then print all of its methods (all using reflection of course). The loading of the ThinkDifferent class works fine but then when I attempt to get its methods I get the exact same NoClassDefFoundError exception. Here is a snippet of my inspection code followed by the output…

Inspection Code in the main() of my app’s main class…

   try {
        final String targetClassName = "processing.core.ThinkDifferent";

        Class<?> targetClass =
           Thread.currentThread().getContextClassLoader().loadClass(targetClassName);
        System.out.println("Driver.main() - loaded class " + targetClass.getName() );

        System.out.println("Driver.main() - list of " + targetClassName + " methods... ");
        Method methods[] = targetClass.getDeclaredMethods();

        for (int i = 0; i < methods.length; i++) {
           System.out.println( methods[i] );
        }
     } catch( Exception e ) {
        System.out.println( "Driver.main() - Caught Exception..." + e );
     }

command line output…

/Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=60496:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/MauiMana/Dev/projects/BuildingScience/Driver/target/classes:/Users/MauiMana/Dev/.m2/repository/org/processing/core/3.3.7/core3.3.7.jar:/Users/MauiMana/Dev/.m2/repository/g4P/g4P/4.3.6/g4P4.3.6.jar:/Users/MauiMana/Dev/projects/BuildingScience/Engineers/target/classes Driver

Driver.main() - loaded class processing.core.ThinkDifferent
Driver.main() - list of processing.core.ThinkDifferent methods... 
Exception in thread "main" java.lang.NoClassDefFoundError: com/apple/eawt/QuitHandler
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3325)
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2466)
	at Driver.main(Driver.java:39)
Caused by: java.lang.ClassNotFoundException: com.apple.eawt.QuitHandler
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 4 more

This is expected. ThinkDifferent relies on code that is no longer in the JDK. Loading a class in that way does not initialize it - check the docs and other class loading methods. It is only when you start reflecting that the class initialization starts, and this triggers the problem.

The only option is to remove that code and recompile (what I’m doing now with libp5x in PraxisLIVE) or possibly strip it from the JAR (what I did do).

I have no idea why ThinkDifferent is loaded via reflection either - it is the code inside it that should be using reflection.