I can not get ProGuard 4.10 to cause a static
method to inline . I only get this with instance methods.
For example, this short stretch:
public final class Calc {
private int x = 0;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
Calc c = new Calc();
int res = c.getX();
if ((c.getX() & 1) != 0)
res++;
else
res += 2;
c.setX(res);
System.out.println(res);
}
}
After rendered by ProGuard it becomes (disregarding the obfuscation):
public final class Calc {
private int x = 0;
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
Calc c = new Calc();
int res = c.x;
if ((c.x & 1) != 0)
res++;
else
res += 2;
c.x = res;
System.out.println(res);
}
}
However, if I adapt the classes, and transform the methods into static
, this section below does not change (disregarding the obfuscation):
public final class Calc {
private static int x = 0;
public static int getX() {
return x;
}
public static void setX(int x) {
Calc.x = x;
}
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
int res = Calc.getX();
if ((Calc.getX() & 1) != 0)
res++;
else
res += 2;
Calc.setX(res);
System.out.println(res);
}
}
To fix any doubt, here's the configuration I'm using in both cases:
-dontskipnonpubliclibraryclassmembers
-optimizationpasses 9
-allowaccessmodification
-mergeinterfacesaggressively
-dontusemixedcaseclassnames
-dontpreverify
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
-keep class * extends java.sql.Driver
-keep class * extends javax.swing.plaf.ComponentUI {
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent);
}
-keepclasseswithmembers,allowshrinking class * {
native <methods>;
}
Am I missing something? Are there any options to make ProGuard optimize and do methods% inline ?
Now these three documents (besides many others) and found nothing mentioning this case. Is this a limitation of ProGuard?