If I have a constant file which uses non-primitive data types like,
public static final Integer xyz = 1;
these constants remain in the constant file even after running the jar with proguard,
but if the constants defined use primitive data type like-
public static final int xyz = 1;
the references to these constants are replaced by the values from the constant file and the constant file is removed all together.
This seems to be a bug. Can anybody throw some light on this?
That's the expected behavior. The javac compiler already inlines primitive constants. ProGuard may then remove the constant fields, which have effectively become unused.
The javac compiler nor ProGuard inline non-primitive constants. That's not possible in general, because you would end up with different instances everywhere the constants are referenced.
But at-least the non-primitive constants that are not being used/referenced from anywhere inside the code, can be removed from the constants files. I de-compiled the constants class and found that these non-referenced constants are not being removed.
Though this observation is not consistent. In one project the constant files are getting cleaned up and in one the files are not getting cleaned up.
Non-primitive constants are initialized in a static code block. This static code often can't be removed due to possible side-effects that ProGuard can't analyze.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.