From 6867f56658604adcd73db084ef82344037ad068f Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 16 Feb 2023 06:56:28 +0000 Subject: [PATCH] Update instrumentation to avoid making all constructors public Previously, any constructors instrumented by Robolectric were made public. This caused two types of issues: 1) If Android classes had non-public constructors which were made public and added to the Android API, Robolectric allowed tests to incorrectly use the constructors on older SDK levels (where they were non-public). This most commonly occurs for AccessibiltyEvent and AccessibilityNodeInfo. 2) When reflection was used to instantiate classes that were instrumented by Robolectric, all constructors were accessible, which did not match what happened when running on an Android test. Update the instrumentation in Robolectric to prevent making all public constructors. PiperOrigin-RevId: 510049123 --- .../mediacodec/AsynchronousMediaCodecCallbackTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecCallbackTest.java b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecCallbackTest.java index 9987710561..31943522ec 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecCallbackTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecCallbackTest.java @@ -460,6 +460,7 @@ public class AsynchronousMediaCodecCallbackTest { Constructor constructor = MediaCodec.CodecException.class.getDeclaredConstructor( Integer.TYPE, Integer.TYPE, String.class); + constructor.setAccessible(true); return constructor.newInstance( /* errorCode= */ 0, /* actionCode= */ 0, /* detailMessage= */ "error from codec"); }