proguard not stripping of unused constants from constant files if these are not primitive types

2013-01-29
2013-02-01
  • ghanshyam gehlot

    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?

     
  • Eric Lafortune

    Eric Lafortune - 2013-01-29

    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.

    Eric

     
    • ghanshyam gehlot

      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.

       
  • Eric Lafortune

    Eric Lafortune - 2013-02-01

    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.

    Eric

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks