Cannot call method of outer class in yguard-obfuscated file
gbl opened this issue · comments
Note that this is similar to https://stackoverflow.com/questions/66350654/unable-to-access-private-fields-and-methods-from-inner-class-after-yguard-obfusc where the answer says it works with yguard 3.0 and should possibly be posted as an issue if the problem persists.
Here's my example.java:
package com.example;
public class Example {
private static void privatemethod() {
System.out.println("in private method");
}
public static void main(String[] args) {
new Thread() {
@Override
public void run() {
privatemethod();
}
}.start();
}
}
// non-static version that goes wrong as well:
// private void privatemethod() {
// new Example().privatemethod();
and here's the yguard part of my build.xml:
<yguard>
<inoutpair in="dist/Example.jar" out="dist/Example-yg.jar"/>
<shrink logfile="dist/shrink.log"/>
<rename mainclass="com.example.Example" logfile="dist/rename.log">
<keep>
<class classes="protected" methods="protected" fields="protected">
<patternset>
<include name="com.example.Example.**"/>
</patternset>
</class>
</keep>
</rename>
</yguard>
Running both files:
gbl@natascha$ java17 -jar dist/Example.jar
in private method
gbl@natascha$ java17 -jar dist/Example-yg.jar
Exception in thread "Thread-0" java.lang.IllegalAccessError: class com.example.Example$1 tried to access private method 'void com.example.Example.A()' (com.example.Example$1 and com.example.Example are in unnamed module of loader 'app')
at com.example.Example$1.run(Unknown Source)
I downloaded the yguard files 2 hours ago, they are version 3.1.0:
-rw-r--r-- 1 gbl gbl 122004 Mar 28 11:57 asm-9.2.jar
-rw-r--r-- 1 gbl gbl 1162 Mar 28 11:57 ObfuscationAnnotation-3.1.0.jar
-rw-r--r-- 1 gbl gbl 451474 Mar 28 11:56 yguard-3.1.0.jar
Here's the complete source directory, including the yguard files in lib/, if it helps in any way. Compile with ant jar
.
Thank you very much for the detailed report and the example files.
This is a bug in yGuard's shrinker (only).
As a workaround, you can rename without shrinking. I.e. remove the line
<shrink logfile="dist/shrink.log"/>
from your <yguard>
task configuration.
Thank you for this valuable task and for fixing this issue!
Any idea when a new official release that includes this fix is planned?
We have not decided yet on a date for the next release.