1616package androidx .test .internal .runner ;
1717
1818import static androidx .test .internal .util .Checks .checkNotNull ;
19+ import static java .nio .charset .StandardCharsets .UTF_8 ;
1920
2021import android .app .Instrumentation ;
2122import android .os .Bundle ;
@@ -53,7 +54,7 @@ private TestExecutor(Builder builder) {
5354 * <p>If an error occurred during the test execution, the exception will be thrown, and it's the
5455 * caller's responsibility to handle the exception properly.
5556 */
56- public Bundle execute (Request request ) throws UnsupportedEncodingException {
57+ public Bundle execute (Request request ) {
5758 Trace .beginSection ("execute tests" );
5859 try {
5960 return execute (new JUnitCore (), request );
@@ -62,7 +63,7 @@ public Bundle execute(Request request) throws UnsupportedEncodingException {
6263 }
6364 }
6465
65- Bundle execute (JUnitCore junitRunner , Request request ) throws UnsupportedEncodingException {
66+ Bundle execute (JUnitCore junitRunner , Request request ) {
6667 Bundle resultBundle = new Bundle ();
6768 setUpListeners (junitRunner );
6869 Result junitResults = junitRunner .run (request );
@@ -72,10 +73,15 @@ Bundle execute(JUnitCore junitRunner, Request request) throws UnsupportedEncodin
7273 try (PrintStream summaryWriter = new PrintStream (summaryStream )) {
7374 reportRunEnded (listeners , summaryWriter , resultBundle , junitResults );
7475 }
75- String summaryOutput = StackTrimmer .getTrimmedSummary (summaryStream .toString ("UTF_8" ));
76- resultBundle .putString (
77- Instrumentation .REPORT_KEY_STREAMRESULT , String .format ("\n %s" , summaryOutput ));
78- return resultBundle ;
76+ try {
77+ // ByteArrayOutputStream.toString(Charset) requires API level 33
78+ String summaryOutput = StackTrimmer .getTrimmedSummary (summaryStream .toString (UTF_8 .name ()));
79+ resultBundle .putString (
80+ Instrumentation .REPORT_KEY_STREAMRESULT , String .format ("\n %s" , summaryOutput ));
81+ return resultBundle ;
82+ } catch (UnsupportedEncodingException e ) {
83+ throw new RuntimeException ("UTF-8 encoding not supported?" , e );
84+ }
7985 }
8086
8187 /** Initialize listeners and add them to the JUnitCore runner */
0 commit comments