Menu

#500 Remove array initialization

v4.5
open
None
4
2014-04-19
2014-03-03
Markus
No

A private static final byte[] field is removed as field, but nevertheless, locally a new byte[] is created an initialized in a static{ .. } code block. The local reference is unused besides initialization. In my optinion, that should also be removed.

This is for ProGuard 4.11, tested with Java 1.6 u20.

Discussion

  • Markus

    Markus - 2014-03-03

    I'm sorry - somehow the summary got lost.

     
  • Eric Lafortune

    Eric Lafortune - 2014-03-03

    Thanks for your observation. As you describe, the array instance is used, because the initialization code writes values to it. ProGuard doesn't remove the instantiation or the initialization code as a result -- a sort of catch-22. Removing the code requires escape analysis, to make sure the array is not used in any other way. Currently, only DexGuard performs escape analysis and indeed removes the array entirely. I may add it to ProGuard at some point, but it doesn't have a high priority.

     
  • Eric Lafortune

    Eric Lafortune - 2014-03-03
    • assigned_to: Eric Lafortune
    • Priority: 5 --> 4
     
  • Markus

    Markus - 2014-03-03

    Many thanks for you analysis and reply.

    Why isn't the static field removed completely by "write only fields removal"?

     
    • Eric Lafortune

      Eric Lafortune - 2014-03-03

      If I'm not mistaking, the field itself should be removed.

       
  • Eric Lafortune

    Eric Lafortune - 2014-04-19
    • summary: A private static final byte[] field is removed as field, but nevertheless, locally a new byte[] is created an initialized in a static{ .. } code block. In my optinion, that should also be removed. This is for ProGuard 4.11, tested with Java 1.6 u20. --> Remove array initialization
     

Log in to post a comment.