Skip to content

Commit a029b36

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Catch LinkageError in addition to ClassNotFoundErrors.
TestRequestBuilder uses Class.forName to load the legacy Suppress annotation and other annotation classes. The call sites currently only catch ClassNotFoundException, but according to the reference docs Class.forName can also throw LinkageError e.g. NoClassDefFoundError. There has been a report of TestRequestBuilder.maybeAddLegacySuppressFilter throwing a fatal NoClassDefFoundError when used with AGP 9.4.0-alpha03. See issuetracker bug 536117227 To make androidx.test.runner more resilient to class loading issues, this commit expands the catch block to also catch Linkage errors PiperOrigin-RevId: 954713113
1 parent 28113ab commit a029b36

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎runner/android_junit_runner/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
**Bug Fixes**
88

9+
* Catch LinkageError when loading annotation classes (b/536117227)
10+
911
**New Features**
1012

1113
* Make perfetto trace sections for tests more identifiable by prefixing with "test:" and using fully qualified class name. (b/204992764)

‎runner/android_junit_runner/java/androidx/test/internal/runner/TestRequestBuilder.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ private void maybeAddLegacySuppressFilter() {
449449
(Class<? extends Annotation>)
450450
Class.forName("android.test.suitebuilder.annotation.Suppress");
451451
filter = filter.intersect(new AnnotationExclusionFilter(legacySuppressClass));
452-
} catch (ClassNotFoundException e) {
452+
} catch (ClassNotFoundException | LinkageError e) {
453453
// ignore
454454
}
455455
}
@@ -817,7 +817,7 @@ private Class<? extends Annotation> loadAnnotationClass(String className) {
817817
try {
818818
Class<?> clazz = Class.forName(className);
819819
return (Class<? extends Annotation>) clazz;
820-
} catch (ClassNotFoundException e) {
820+
} catch (ClassNotFoundException | LinkageError e) {
821821
Log.e(TAG, String.format("Could not find annotation class: %s", className));
822822
} catch (ClassCastException e) {
823823
Log.e(TAG, String.format("Class %s is not an annotation", className));

0 commit comments

Comments
 (0)