Skip to content

Commit 62c22b7

Browse files
authored
test(spanner): disable annotation copying on ServerStream mocks causing Java 8 crash (#13832)
### Problem In JSpecify 1.0.0, the `@NullMarked` annotation targets `ElementType.MODULE`. Because `ElementType.MODULE` was introduced in Java 9, reflecting on `@NullMarked` classes under Java 8 (JDK 1.8) throws `EnumConstantNotPresentExceptionProxy` wrapped in an `ArrayStoreException`. In `PartitionedDmlTransactionTest`, two mock declarations for `ServerStream` were created using the default `mock(ServerStream.class)` without setting `.withoutAnnotations()`. Mockito attempts to copy annotations on the mock subclasses, triggering the reflection crash on the JSpecify `@NullMarked` annotation during Java 8 CI pipelines. ### Solution Replaced `mock(ServerStream.class)` with `mock(ServerStream.class, withSettings().withoutAnnotations())` in `testExecuteStreamingPartitionedUpdateRSTstream` and `testExecuteStreamingPartitionedUpdateGenericInternalException` to match the other passing tests. This disables annotation copying on the mocked `ServerStream` instances and bypasses the Java 8 reflection limitations.
1 parent 3700cf4 commit 62c22b7

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ public void testExecuteStreamingPartitionedUpdateRSTstream() {
370370
ResultSetStats stats = ResultSetStats.newBuilder().setRowCountLowerBound(1000L).build();
371371
PartialResultSet p1 = PartialResultSet.newBuilder().setResumeToken(resumeToken).build();
372372
PartialResultSet p2 = PartialResultSet.newBuilder().setStats(stats).build();
373-
ServerStream<PartialResultSet> stream1 = mock(ServerStream.class);
373+
ServerStream<PartialResultSet> stream1 =
374+
mock(ServerStream.class, withSettings().withoutAnnotations());
374375
Iterator<PartialResultSet> iterator = mock(Iterator.class);
375376
when(iterator.hasNext()).thenReturn(true, true, false);
376377
when(iterator.next())
@@ -382,7 +383,8 @@ public void testExecuteStreamingPartitionedUpdateRSTstream() {
382383
GrpcStatusCode.of(Code.INTERNAL),
383384
true));
384385
when(stream1.iterator()).thenReturn(iterator);
385-
ServerStream<PartialResultSet> stream2 = mock(ServerStream.class);
386+
ServerStream<PartialResultSet> stream2 =
387+
mock(ServerStream.class, withSettings().withoutAnnotations());
386388
when(stream2.iterator()).thenReturn(ImmutableList.of(p1, p2).iterator());
387389
when(rpc.executeStreamingPartitionedDml(
388390
Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(), any(Duration.class)))
@@ -407,7 +409,8 @@ public void testExecuteStreamingPartitionedUpdateRSTstream() {
407409
@Test
408410
public void testExecuteStreamingPartitionedUpdateGenericInternalException() {
409411
PartialResultSet p1 = PartialResultSet.newBuilder().setResumeToken(resumeToken).build();
410-
ServerStream<PartialResultSet> stream1 = mock(ServerStream.class);
412+
ServerStream<PartialResultSet> stream1 =
413+
mock(ServerStream.class, withSettings().withoutAnnotations());
411414
Iterator<PartialResultSet> iterator = mock(Iterator.class);
412415
when(iterator.hasNext()).thenReturn(true, true, false);
413416
when(iterator.next())

0 commit comments

Comments
 (0)