You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: Disable copying annotation on mocks for Java 8 CIs (#13702)
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`
Copy file name to clipboardExpand all lines: java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientV2Test.java
Copy file name to clipboardExpand all lines: java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnectionTest.java
Copy file name to clipboardExpand all lines: java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerCloudMonitoringExporterTest.java
+3-7Lines changed: 3 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -72,13 +72,9 @@
72
72
importjava.util.stream.Collectors;
73
73
importorg.junit.After;
74
74
importorg.junit.Before;
75
-
importorg.junit.Rule;
76
75
importorg.junit.Test;
77
76
importorg.mockito.ArgumentCaptor;
78
-
importorg.mockito.Mock;
79
77
importorg.mockito.Mockito;
80
-
importorg.mockito.junit.MockitoJUnit;
81
-
importorg.mockito.junit.MockitoRule;
82
78
83
79
publicclassSpannerCloudMonitoringExporterTest {
84
80
@@ -91,9 +87,7 @@ public class SpannerCloudMonitoringExporterTest {
0 commit comments