Skip to content

test(storage-nio): disable copying annotations for storage-nio#13830

Merged
nnicolee merged 2 commits into
mainfrom
test/disable-storage-nio-annotations-mock
Jul 20, 2026
Merged

test(storage-nio): disable copying annotations for storage-nio#13830
nnicolee merged 2 commits into
mainfrom
test/disable-storage-nio-annotations-mock

Conversation

@nnicolee

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

@nnicolee
nnicolee marked this pull request as ready for review July 20, 2026 04:47
@nnicolee
nnicolee requested review from a team as code owners July 20, 2026 04:47

@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 the test cases in CloudStorageIsDirectoryTest.java to mock the Page class without annotations using Mockito.mock(Page.class, Mockito.withSettings().withoutAnnotations()) instead of a simple mock. There are no review comments, and I have no additional feedback to provide.

@nnicolee
nnicolee merged commit 3700cf4 into main Jul 20, 2026
206 checks passed
@nnicolee
nnicolee deleted the test/disable-storage-nio-annotations-mock branch July 20, 2026 15:25
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