Skip to content

Commit

Permalink
test: skip SpanTest when NoSuchFieldException (#2084)
Browse files Browse the repository at this point in the history
* test: skip SpanTest when NoSuchFieldException

Latest internal jdk 11 build throws NoSuchFieldException when we use reflection on a reflection class. Gracefully skipping the test execution in that case.
  • Loading branch information
rajatbhatta authored Sep 29, 2022
1 parent de8d120 commit 98c2303
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ public static void startStaticServer() throws Exception {
// This is not possible in Java 12 and later.
java.lang.reflect.Field field = Tracing.class.getDeclaredField("traceComponent");
field.setAccessible(true);
java.lang.reflect.Field modifiersField =
java.lang.reflect.Field.class.getDeclaredField("modifiers");
java.lang.reflect.Field modifiersField = null;
try {
modifiersField = java.lang.reflect.Field.class.getDeclaredField("modifiers");
} catch (NoSuchFieldException e) {
// Halt the test and ignore it.
Assume.assumeTrue(
"Skipping test as reflection is not allowed on reflection class in this JDK build",
false);
}
modifiersField.setAccessible(true);
// Remove the final modifier from the 'traceComponent' field.
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
Expand Down

0 comments on commit 98c2303

Please sign in to comment.