Skip to content

binder: compile warnings; RequiresPermission missing, readParcelable(ClassLoader) deprecated #10297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ejona86 opened this issue Jun 23, 2023 · 4 comments · Fixed by #10989
Closed

Comments

@ejona86
Copy link
Member

ejona86 commented Jun 23, 2023

The following warnings prevent building grpc-binder with -PfailOnWarnings=true, which sets -Werror. class file for android.annotation.RequiresPermission not found in particular is pretty nasty as it isn't clear what is going on and you can't silence the single warning.

> Task :grpc-binder:compileDebugUnitTestJavaWithJavac
grpc-java/binder/src/test/java/io/grpc/binder/internal/ParcelableInputStreamTest.java:91: warning: [deprecation] <T>readParcelable(ClassLoader) in Parcel has been deprecated
    assertThat((TestParcelable) parcel.readParcelable(getClass().getClassLoader()))
                                      ^
  where T is a type-variable:
    T extends Parcelable declared in method <T>readParcelable(ClassLoader)
grpc-java/binder/src/test/java/io/grpc/binder/internal/ParcelableInputStreamTest.java:116: warning: [deprecation] <T>readParcelable(ClassLoader) in Parcel has been deprecated
    assertThat((TestParcelable) parcel.readParcelable(getClass().getClassLoader()))
                                      ^
  where T is a type-variable:
    T extends Parcelable declared in method <T>readParcelable(ClassLoader)
~/.gradle/caches/modules-2/files-2.1/org.robolectric/shadows-framework/4.9.2/8854520515f61e7f8319534dbbea3071cd282c54/shadows-framework-4.9.2.jar(/org/robolectric/shadows/ShadowDevicePolicyManager.class): warning: Cannot find annotation method 'value()' in type 'RequiresPermission': class file for android.annotation.RequiresPermission not found
~/.gradle/caches/modules-2/files-2.1/org.robolectric/shadows-framework/4.9.2/8854520515f61e7f8319534dbbea3071cd282c54/shadows-framework-4.9.2.jar(/org/robolectric/shadows/ShadowDevicePolicyManager.class): warning: Cannot find annotation method 'value()' in type 'RequiresPermission'
~/.gradle/caches/modules-2/files-2.1/org.robolectric/shadows-framework/4.9.2/8854520515f61e7f8319534dbbea3071cd282c54/shadows-framework-4.9.2.jar(/org/robolectric/shadows/ShadowDevicePolicyManager.class): warning: Cannot find annotation method 'value()' in type 'RequiresPermission'
~/clients/grpc-java/binder/src/test/java/io/grpc/binder/SecurityPoliciesTest.java:532: warning: [deprecation] signatures in PackageInfo has been deprecated
        packageInfo.signatures = this.signatures;
                   ^
6 warnings

CC @markb74, @jdcormie

@ejona86 ejona86 added this to the Next milestone Jun 23, 2023
@markb74
Copy link
Contributor

markb74 commented Jun 23, 2023

We'll need to suppress the both the readParcelable and signatures warnings.

The new readParcelable method doesn't exist before Android 13, and the signatures code is testing support for older Android versions.

The RequiresPermission one seems to be an issue in robolectric?

@ejona86
Copy link
Member Author

ejona86 commented Jun 23, 2023

Yeah, I agree, but at the very least we can add @SuppressWarnings("deprecations") with a comment to the code. I would have done that in #10299 (where this came up), but that RequiresPermission thing was super strange.

It does seem an issue with Robolectric, but I'm also not clear on why Robolectric would be using the private versions of those annotations. I did try upgrading to the newest Robolectric and the issue was still present.

@jdcormie
Copy link
Member

jdcormie commented Mar 5, 2024

I found https://github.com/robolectric/robolectric/blob/master/ARCHITECTURE.md#android-framework-jars-and-instrumentation, which explains why robolectric shadows are able to depend on non-SDK Android classes marked @hide, such as android.annotation.RequiresPermission. I found that I can make the warnings go away by adding:

testCompileOnly "org.robolectric:android-all-instrumented:14-robolectric-10818077-i5"

but I'm not sure if that's the right fix. Many other projects appear to do this.

@ejona86
Copy link
Member Author

ejona86 commented Mar 5, 2024

If a compile-only dep fixes it, that seems low risk and easy.

jdcormie added a commit to jdcormie/grpc-java that referenced this issue Mar 6, 2024
@ejona86 ejona86 modified the milestones: Next, 1.63 Mar 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants