test(spanner): apply withoutAnnotations to all GAX mocks for Java 8 compatibility#13820
Conversation
…ompatibility Apply Mockito's withSettings().withoutAnnotations() to all mocks of GAX interfaces and classes across google-cloud-spanner tests to prevent Java 8 ArrayStoreException during reflection over JSpecify type-use annotations. TAG=agy CONV=b24aa6bb-9ced-468d-ab05-50b3c30e9228
There was a problem hiding this comment.
Code Review
This pull request updates several test files to mock classes using withSettings().withoutAnnotations() to prevent ArrayStoreException issues on Java 8 caused by JSpecify type-use annotations. The review feedback points out that child3 of type OpenTelemetryApiTracer in CompositeTracerTest.java is still annotated with @Mock, which will likely trigger the same Java 8 compatibility issue, and suggests mocking it manually with disabled annotations as well.
| private ApiTracer child1; | ||
| private ApiTracer child2; | ||
| @Mock private OpenTelemetryApiTracer child3; | ||
| @Mock private MetricsTracer child4; | ||
| private MetricsTracer child4; | ||
|
|
||
| private CompositeTracer compositeTracer; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| child1 = mock(ApiTracer.class, withSettings().withoutAnnotations()); | ||
| child2 = mock(ApiTracer.class, withSettings().withoutAnnotations()); | ||
| child4 = mock(MetricsTracer.class, withSettings().withoutAnnotations()); | ||
| compositeTracer = new CompositeTracer(ImmutableList.of(child1, child2, child3, child4)); |
There was a problem hiding this comment.
The child3 field of type OpenTelemetryApiTracer is still annotated with @Mock. Since OpenTelemetryApiTracer implements ApiTracer (a GAX interface), mocking it without disabling annotations will trigger the same ArrayStoreException on Java 8 due to JSpecify type-use annotations. To ensure full Java 8 compatibility, child3 should also be mocked manually using withSettings().withoutAnnotations().
private ApiTracer child1;
private ApiTracer child2;
private OpenTelemetryApiTracer child3;
private MetricsTracer child4;
private CompositeTracer compositeTracer;
@Before
public void setup() {
child1 = mock(ApiTracer.class, withSettings().withoutAnnotations());
child2 = mock(ApiTracer.class, withSettings().withoutAnnotations());
child3 = mock(OpenTelemetryApiTracer.class, withSettings().withoutAnnotations());
child4 = mock(MetricsTracer.class, withSettings().withoutAnnotations());
compositeTracer = new CompositeTracer(ImmutableList.of(child1, child2, child3, child4));
Apply Mockito's withSettings().withoutAnnotations() to all mocks of GAX interfaces and classes across google-cloud-spanner tests to prevent Java 8 ArrayStoreException during reflection over JSpecify type-use annotations.