I have the following class.
package myPackage.handlers;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import org.eclipse.core.commands.AbstractHandler;
public class MyHandler extends AbstractHandler {
@Override
public Object execute( ExecutionEvent event ) throws ExecutionException {
ActionListener myListener = new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
// do something here
}
};
Timer myTimer = new Timer( 2000, myListener );
myTimer.start();
}
}
When it is obfuscated, the anonymous class (new ActionListener) is placed on a new file (MyHandler$1.class)
If I compile it for Java 8, the actionPerformed method is there.
But if compile it for Java 17, the actionPerformed method is removed, leading to java.lang.AbstractMethodErrors being thrown at runtime.
When compiling for Java 8, the ProGuard settings are these:
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-keepattributes SourceFile, LineNumberTable, RuntimeVisibleParameterAnnotations, RuntimeVisibleAnnotations
-keep class * implements org.eclipse.core.commands.AbstractHandler
When compiling for Java 17, the settings are the same, with the addition of:
-libraryjars C:/pathToMyJava/jmods/java.base.jmod(!**.jar;!module-info.class)
Some tests I did while trying to figure it out:
- Add some other methods on the anonymous class: none of them is present on the .class file.
- Add a call to myListener.actionPerformed() in the end of the execute method: the line is not present on the MyHandler.class file.
- Add a call to System.out.println( myListener ) in the end of the execute method: the line is not present on the MyHandler.class file.
Iād like to get some insight on what could I do to understand why is the method being removed.