Skip to content

test: Disable copying annotation on mocks for Java 8 CIs#13702

Merged
nnicolee merged 7 commits into
mainfrom
test-withoutannotations
Jul 8, 2026
Merged

test: Disable copying annotation on mocks for Java 8 CIs#13702
nnicolee merged 7 commits into
mainfrom
test-withoutannotations

Conversation

@nnicolee

@nnicolee nnicolee commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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 generated stub and settings classes that are annotated with @NullMarked.

To bypass this Java 8 limitation:

  • Replaced default Mockito mock instantiation with Mockito.mock(Class, Mockito.withSettings().withoutAnnotations()) across the failing unit test suites.
  • 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:

  • StreamingSubscriberConnectionTest
  • SpannerImplTest
  • SpannerCloudMonitoringExporterTest
  • BigtableInstanceAdminClientV2Test
  • BigtableTableAdminClientV2Test
  • BigtableCloudMonitoringExporterTest
  • GrpcLongRunningClientTest

@nnicolee nnicolee requested a review from lqiu96 July 8, 2026 15:34

@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 refactors several test classes across different modules to instantiate Mockito mocks explicitly using withSettings().withoutAnnotations() instead of using @Mock annotations or standard mock() calls. The feedback suggests removing the now-unused mockitoRule fields and their associated imports in SpannerCloudMonitoringExporterTest and BigtableTableAdminClientV2Test since no @Mock annotations remain in those classes.

@Rule public final MockitoRule mockitoRule = MockitoJUnit.rule();

@Mock private MetricServiceStub mockMetricServiceStub;
private MetricServiceStub mockMetricServiceStub;

This comment was marked as resolved.

"projects/my-project/instances/my-instance/tables/my-table";

@Mock private GrpcBigtableTableAdminStub mockStub;
private GrpcBigtableTableAdminStub mockStub;

This comment was marked as resolved.

@nnicolee nnicolee marked this pull request as ready for review July 8, 2026 16:56
@nnicolee nnicolee requested review from a team as code owners July 8, 2026 16:56

@lqiu96 lqiu96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM for GAX

@lqiu96 lqiu96 changed the title fix: disable annotation on mocks for java 8 test: Disable copying annotation on mocks for Java 8 CIs Jul 8, 2026
@nnicolee nnicolee enabled auto-merge (squash) July 8, 2026 20:29
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@nnicolee nnicolee merged commit 24241c9 into main Jul 8, 2026
311 of 319 checks passed
@nnicolee nnicolee deleted the test-withoutannotations branch July 8, 2026 22:03
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.

5 participants