From 287cc3a5707e5fa0981a4fb7e245779f20c56f56 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 8 Feb 2023 16:30:12 +0000 Subject: [PATCH] Fix tests affected by Robolectric's constructor visibility bug Previously, Robolectric's instrumentation updated all constructors to be public. This caused two main types of problems: 1) When non-public constructors 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. Fix issues across Google3 Robolectric tests that were affected by this issue. A forthcoming change will fix the instrumentation in Robolectric to prevent this type of issue from occurring. Tested: TAP --sample ran all affected tests and none failed http://test/OCL:507861075:BASE:507805409:1675803313108:f2128fa4 PiperOrigin-RevId: 508087822 --- .../exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java index 9aa2b5f3ba..819ffd89bd 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java @@ -192,6 +192,7 @@ public class AsynchronousMediaCodecAdapterTest { 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"); }