context: Skip storageReturnsNullTest for JDK >= 11 (#9484)

JDK-8210522 changes the behaviour of Java reflection to filter out
security-sensitive fields in the java.lang.reflect.Field. This
prohibits Field.class.getDeclaredFields("modifiers") call we rely on
in this test. Until we have a good solution for setting a custom
storage for testing purposes, we'll have to skip this test
for JDK >= 11. Ref https://bugs.openjdk.org/browse/JDK-8210522
This commit is contained in:
Sergii Tkachenko 2022-08-24 10:17:12 -07:00 committed by GitHub
parent e1ddc3553f
commit 0cf2d8bc48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -16,6 +16,7 @@
package io.grpc; package io.grpc;
import static com.google.common.truth.TruthJUnit.assume;
import static io.grpc.Context.cancellableAncestor; import static io.grpc.Context.cancellableAncestor;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsInstanceOf.instanceOf;
@ -872,6 +873,20 @@ public class ContextTest {
@Test @Test
public void storageReturnsNullTest() throws Exception { public void storageReturnsNullTest() throws Exception {
// TODO(sergiitk): JDK-8210522 changes the behaviour of Java reflection to filter out
// security-sensitive fields in the java.lang.reflect.Field. This prohibits
// Field.class.getDeclaredFields("modifiers") call we rely on in this test.
// Until we have a good solution for setting a custom storage for testing purposes,
// we'll have to skip this test for JDK >= 11. Ref https://bugs.openjdk.org/browse/JDK-8210522
double javaVersion;
// Graceful version check. Run the test if the version undetermined.
try {
javaVersion = Double.parseDouble(System.getProperty("java.specification.version", "0"));
} catch (NumberFormatException e) {
javaVersion = 0;
}
assume().that(javaVersion).isLessThan(11);
Class<?> lazyStorageClass = Class.forName("io.grpc.Context$LazyStorage"); Class<?> lazyStorageClass = Class.forName("io.grpc.Context$LazyStorage");
Field storage = lazyStorageClass.getDeclaredField("storage"); Field storage = lazyStorageClass.getDeclaredField("storage");
assertTrue(Modifier.isFinal(storage.getModifiers())); assertTrue(Modifier.isFinal(storage.getModifiers()));