rharter / auto-value-parcel

An Android Parcelable extension for Google's AutoValue.
Apache License 2.0
655 stars 64 forks source link

Add @SuppressWarnings annotations to handle templated AutoValues when using -Werror #160

Closed mateusazis closed 1 year ago

mateusazis commented 1 year ago

My project invokes javac with -Werror, which treats warnings as errors and blocks compilations. When an AutoValue carries a parameterized Parcelable, like:

@AutoValue
abstract class Foo<T> {
  abstract Parcelable<T> bar();
  // ...
}

Then it yields:

public static final Parcelable.Creator<AutoValue_Foo<?>> CREATOR = new Parcelable.Creator<AutoValue_Foo<?>> {
  @Override
  public AutoValue_Foo<?> createFromParcel(Parcel in) {
    return (AutoValue_Foo<?>) new AutoValue_Foo(
      (Bar<?>) in.readParcelable(Bar.class.getClassLoader()) );
  }
  @Override
  public AutoValue_Test<? extends String, ? extends System>[] newArray(int size) {
    return new AutoValue_Test[size];
  }
};

Where both createFromParcel and newArray raise unchecked (from the typecast) and rawtypes (from calling the constructor without specifying the template type) warnings.

This CL the proper suppression so that such code will compile even with -Werror.

benjoseph commented 1 year ago

Is there a release planned with this change?