Menu

#406 Generic Field information for kept classes should be kept

v4.6
closed-works-for-me
None
5
2011-12-26
2011-07-23
Anonymous
No

I am one of the coauthors of Gson library (a Java to JSON conversion tool). Several users use our library in Android projects. Gson uses reflection to bind Java fields to JSON fields. Gson also supports generic fields. For example, a List<LineItem> will be mapped to a JSON array of LineItem. To do this binding correctly, Gson uses the reflection on the fields to get the parameterized type (note that Type erasure does not affect the fields of a class).

However, it seems like when proguard is run on an Android app with Gson, this generic type information stored for a field is lost. A field of type List<LineItem> becomes of type List. This means that Gson no longer has enough information to do the data binding correctly.

I have written an example Android application that demonstrates this behavior. Please see:
http://code.google.com/p/google-gson/source/browse/#svn%2Ftrunk%2Fexamples%2Fandroid-proguard-example

In specific, Change list http://code.google.com/p/google-gson/source/detail?r=877 has the code that shows that proguard is erasing type information.

Please provide a fix to ensure that generic information is saved for fields of classes kept with --keep.

Discussion

  • Eric Lafortune

    Eric Lafortune - 2011-07-23
    • assigned_to: nobody --> lafortune
    • status: open --> open-works-for-me
     
  • Eric Lafortune

    Eric Lafortune - 2011-07-23

    By default, ProGuard indeed removes generic type information, since the JVM doesn't use it. This information is stored in attributes. If you want to keep them, you have to add this option:

    -keepattributes Signature

    This is illustrated in the ProGuard Manual > Examples > A typical library

     
  • Eric Lafortune

    Eric Lafortune - 2011-12-26
    • status: open-works-for-me --> closed-works-for-me
     

Log in to post a comment.