Skip to content

Commit 98c2303

Browse files
authored
test: skip SpanTest when NoSuchFieldException (#2084)
* 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.
1 parent de8d120 commit 98c2303

File tree

1 file changed

+9
-2
lines changed
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner

1 file changed

+9
-2
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ public static void startStaticServer() throws Exception {
110110
// This is not possible in Java 12 and later.
111111
java.lang.reflect.Field field = Tracing.class.getDeclaredField("traceComponent");
112112
field.setAccessible(true);
113-
java.lang.reflect.Field modifiersField =
114-
java.lang.reflect.Field.class.getDeclaredField("modifiers");
113+
java.lang.reflect.Field modifiersField = null;
114+
try {
115+
modifiersField = java.lang.reflect.Field.class.getDeclaredField("modifiers");
116+
} catch (NoSuchFieldException e) {
117+
// Halt the test and ignore it.
118+
Assume.assumeTrue(
119+
"Skipping test as reflection is not allowed on reflection class in this JDK build",
120+
false);
121+
}
115122
modifiersField.setAccessible(true);
116123
// Remove the final modifier from the 'traceComponent' field.
117124
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

0 commit comments

Comments
 (0)