tom91136 / Akatsuki

Android states and arguments made easy with annotations
Apache License 2.0
138 stars 15 forks source link

Generic type not dynamically generated in generated class #6

Closed ersin-ertan closed 9 years ago

ersin-ertan commented 9 years ago

Should the generic class type T in the BundleRetainer class be of the same type in MyBean class of Typ? If not, there could be a type naming clash if I had used T in MyBean and the generated T did not check to see if its name collided with the one in MyBean.

public class MyBean<Typ extends String> extends RootBean{
    @Retained public Typ     retainedGeneric;
}

public class MyBean$$BundleRetainer<T extends MyBean> extends RootBean$$BundleRetainer<T> {
  public void save(final T source, final Bundle bundle) {
    super.save(source, bundle);
    bundle.putString("retainedGeneric", source.retainedGeneric);
    bundle.putBundle("model", com.sora.util.akatsuki.Akatsuki.serialize(source.model));
  }

  public void restore(final T source, final Bundle bundle) {
    super.restore(source, bundle);
    source.retainedGeneric = (Typ)bundle.getString("retainedGeneric");
    source.model = com.sora.util.akatsuki.Akatsuki.deserialize(source.model, bundle.getBundle("model"));
  }
}
tom91136 commented 9 years ago

I found the cause(The test passed because it was relying on the fact that Bundle.getParcelable has a generic factory). Working on a fix.

tom91136 commented 9 years ago

Please upgrade to 0.0.3 as this is a serious bug that might let cast errors go undetected at compile-time