Skip to content

Commit 3700cf4

Browse files
authored
test(storage-nio): disable copying annotations for storage-nio (#13830)
In JSpecify 1.0.0, the `@NullMarked` annotation includes `ElementType.MODULE` in its `@Target` metadata. Because `ElementType.MODULE` was introduced in Java 9, reflecting on `@NullMarked` classes under Java 8 (JDK 1.8) throws `EnumConstantNotPresentExceptionProxy` wrapped in an `ArrayStoreException`. When unit tests run on Java 8, Mockito's default mock generation (via ByteBuddy) attempts to copy all runtime class annotations from target classes onto mock subclasses. This triggers the reflection crash when mocking `Page` classes that are transitively annotated with `@NullMarked`. To bypass this Java 8 limitation: * Replaced default Mockito mock instantiation of `Page` classes with `Mockito.mock(Page.class, Mockito.withSettings().withoutAnnotations())` in `CloudStorageIsDirectoryTest`. * Disabling annotation copying prevents Mockito/ByteBuddy from invoking `Class.getAnnotations()` on the target class during proxy creation, allowing tests to run and mock stubs successfully on Java 8 pipelines. Modified Mockito mock setups in: * `CloudStorageIsDirectoryTest`
1 parent 13964f2 commit 3700cf4

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

java-storage-nio/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageIsDirectoryTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.junit.rules.TestName;
3737
import org.junit.runner.RunWith;
3838
import org.junit.runners.JUnit4;
39+
import org.mockito.Mockito;
3940

4041
/** Unit tests for {@code Files.isDirectory()}. */
4142
@RunWith(JUnit4.class)
@@ -69,7 +70,7 @@ public void testIsDirectoryNoUserProject() {
6970
CloudStorageFileSystem.forBucket("bucket", CloudStorageConfiguration.DEFAULT, mockOptions);
7071
when(mockStorage.get(BlobId.of("bucket", "test", null)))
7172
.thenThrow(new IllegalArgumentException());
72-
Page<Blob> pages = mock(Page.class);
73+
Page<Blob> pages = Mockito.mock(Page.class, Mockito.withSettings().withoutAnnotations());
7374
Blob blob = mock(Blob.class);
7475
when(blob.getBlobId()).thenReturn(BlobId.of("bucket", "test/hello.txt"));
7576
when(pages.getValues()).thenReturn(Lists.newArrayList(blob));
@@ -91,7 +92,7 @@ public void testIsDirectoryWithUserProject() {
9192
mockOptions);
9293
when(mockStorage.get(BlobId.of("bucket", "test", null)))
9394
.thenThrow(new IllegalArgumentException());
94-
Page<Blob> pages = mock(Page.class);
95+
Page<Blob> pages = Mockito.mock(Page.class, Mockito.withSettings().withoutAnnotations());
9596
Blob blob = mock(Blob.class);
9697
when(blob.getBlobId()).thenReturn(BlobId.of("bucket", "test/hello.txt"));
9798
when(pages.getValues()).thenReturn(Lists.newArrayList(blob));

0 commit comments

Comments
 (0)