Skip to content

test(spanner): apply withoutAnnotations to all GAX mocks for Java 8 compatibility#13820

Merged
lqiu96 merged 1 commit into
mainfrom
fix-spanner-mockito-without-annotations
Jul 17, 2026
Merged

test(spanner): apply withoutAnnotations to all GAX mocks for Java 8 compatibility#13820
lqiu96 merged 1 commit into
mainfrom
fix-spanner-mockito-without-annotations

Conversation

@lqiu96

@lqiu96 lqiu96 commented Jul 17, 2026

Copy link
Copy Markdown
Member

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.

…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
@lqiu96
lqiu96 requested review from a team as code owners July 17, 2026 21:45

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +50 to 62
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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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));

@lqiu96
lqiu96 enabled auto-merge (squash) July 17, 2026 21:51
@lqiu96
lqiu96 merged commit 1bc16bb into main Jul 17, 2026
207 checks passed
@lqiu96
lqiu96 deleted the fix-spanner-mockito-without-annotations branch July 17, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants