Skip to content

Avoid mocking of internal static utilities#3785

Merged
raphw merged 1 commit intomainfrom
avoid-static-utilities
Feb 6, 2026
Merged

Avoid mocking of internal static utilities#3785
raphw merged 1 commit intomainfrom
avoid-static-utilities

Conversation

@raphw
Copy link
Copy Markdown
Member

@raphw raphw commented Jan 19, 2026

Avoids mocking private static methods, as well as package-private static methods of java.* classes, as those are primarily internal utilities that will cause non-intuitive changes of methods. This are not invoked for non-static mocks either. Fixes #3778.

Minor risk: people might have relied on stubbing those internal methods.

…tic methods of java.* classes, as those are primarily internal utilities that will cause non-intuitive changes of methods. This are not invoked for non-static mocks either. Fixes #3778.
@raphw raphw requested a review from bric3 January 19, 2026 19:57
Copy link
Copy Markdown
Contributor

@bric3 bric3 left a comment

Choose a reason for hiding this comment

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

Totally agree
Do you have a story behind this change. Is it related to JEP 500?

Comment on lines +136 to +146
isStatic()
.and(
not(
isPrivate()
.or(
isDeclaredBy(
nameStartsWith(
"java."))
.<MethodDescription>
and(
isPackagePrivate()))))
Copy link
Copy Markdown
Contributor

@bric3 bric3 Jan 19, 2026

Choose a reason for hiding this comment

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

ouch the alignment. We need to look into spotless rules. This doesn't make sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, I agree. Will not build otherwise right now, though.

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.

Yep I assumed 😞

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.49%. Comparing base (d16fcfc) to head (c4c0127).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3785      +/-   ##
============================================
+ Coverage     86.48%   86.49%   +0.01%     
  Complexity     2989     2989              
============================================
  Files           341      341              
  Lines          9041     9050       +9     
  Branches       1113     1113              
============================================
+ Hits           7819     7828       +9     
  Misses          941      941              
  Partials        281      281              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raphw
Copy link
Copy Markdown
Member Author

raphw commented Jan 19, 2026

It only fails with Java 25 because they changed the internal implementation to use private static utilities which are now mocked. Before, the code was inlined in the method, so it worked for instances. That's why I think that is a better default.

@TimvdLippe
Copy link
Copy Markdown
Contributor

Can we reuse the @DoNotMock infrastructure? https://github.com/mockito/mockito/blob/main/mockito-core/src/main/java/org/mockito/DoNotMock.java has the annotation, but I believe we have some other custom lists as well. We block mocking List if I remember correctly.

@raphw
Copy link
Copy Markdown
Member Author

raphw commented Jan 19, 2026

In this case, it is about methods of classes, not the class in general. Also, it those are not referencable by the API. I think this is the right approach here.

@alwibrm
Copy link
Copy Markdown

alwibrm commented Feb 3, 2026

Hi, will this be merged soon? This behaviour in Mockito is currently preventing us from upgrading to Java 25.

@raphw raphw merged commit ef9ee55 into main Feb 6, 2026
19 checks passed
@raphw raphw deleted the avoid-static-utilities branch February 6, 2026 15:23
dongjoon-hyun added a commit to apache/spark that referenced this pull request Mar 20, 2026
…o-5-18`

### What changes were proposed in this pull request?

This PR upgrades `mockito-core` to 5.23.0 and the corresponding `scalatestplus-mockito` to `mockito-5-18` to avoid any future Java 21 and 25 testing issue.

### Why are the changes needed?

Currently, we are using 5.12.0 which was released on 2024-05-11.

We had better keep the test dependency up to date with the latest bug fixes and improvements.
- https://github.com/mockito/mockito/releases/tag/v5.23.0
- https://github.com/mockito/mockito/releases/tag/v5.22.0
  - mockito/mockito#3778
  - mockito/mockito#3785
- https://github.com/mockito/mockito/releases/tag/v5.21.0
  - mockito/mockito#3758
- https://github.com/mockito/mockito/releases/tag/v5.20.0
  - mockito/mockito#3708
- https://github.com/mockito/mockito/releases/tag/v5.19.0
  - mockito/mockito#3659
- https://github.com/mockito/mockito/releases/tag/v5.18.0
- https://github.com/mockito/mockito/releases/tag/v5.17.0
- https://github.com/mockito/mockito/releases/tag/v5.16.0
- https://github.com/mockito/mockito/releases/tag/v5.15.0
  - mockito/mockito#3476
- https://github.com/mockito/mockito/releases/tag/v5.14.0
- https://github.com/mockito/mockito/releases/tag/v5.13.0

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (claude-opus-4-6)

Closes #54915 from dongjoon-hyun/SPARK-56098.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
dongjoon-hyun added a commit to apache/spark-kubernetes-operator that referenced this pull request Mar 20, 2026
### What changes were proposed in this pull request?

This PR upgrades `mockito` to 5.23.0 to bring Java 25 related bug fix.

### Why are the changes needed?

To keep the test dependency up to date with the latest bug fixes.
- https://github.com/mockito/mockito/releases/tag/v5.23.0
- https://github.com/mockito/mockito/releases/tag/v5.22.0
  - mockito/mockito#3778
  - mockito/mockito#3785

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs with the existing tests.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (claude-opus-4-6)

Closes #557 from dongjoon-hyun/SPARK-56096.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
dongjoon-hyun added a commit to apache/orc that referenced this pull request Mar 21, 2026
### What changes were proposed in this pull request?

This PR upgrades `mockito` to 5.23.0 to bring Java 25 related bug fix.

### Why are the changes needed?

To keep the test dependency up to date with the latest bug fixes.
- https://github.com/mockito/mockito/releases/tag/v5.23.0
- https://github.com/mockito/mockito/releases/tag/v5.22.0
  - mockito/mockito#3778
  - mockito/mockito#3785

### How was this patch tested?

Pass the CIs with the existing tests.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (claude-opus-4-6)

Closes #2585 from dongjoon-hyun/ORC-2135.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
dongjoon-hyun added a commit to apache/orc that referenced this pull request Mar 21, 2026
### What changes were proposed in this pull request?

This PR upgrades `mockito` to 5.23.0 to bring Java 25 related bug fix.

### Why are the changes needed?

To keep the test dependency up to date with the latest bug fixes.
- https://github.com/mockito/mockito/releases/tag/v5.23.0
- https://github.com/mockito/mockito/releases/tag/v5.22.0
  - mockito/mockito#3778
  - mockito/mockito#3785

### How was this patch tested?

Pass the CIs with the existing tests.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (claude-opus-4-6)

Closes #2585 from dongjoon-hyun/ORC-2135.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit 25d32b7)
Signed-off-by: Dongjoon Hyun <[email protected]>
terana pushed a commit to terana/spark that referenced this pull request Mar 23, 2026
…o-5-18`

### What changes were proposed in this pull request?

This PR upgrades `mockito-core` to 5.23.0 and the corresponding `scalatestplus-mockito` to `mockito-5-18` to avoid any future Java 21 and 25 testing issue.

### Why are the changes needed?

Currently, we are using 5.12.0 which was released on 2024-05-11.

We had better keep the test dependency up to date with the latest bug fixes and improvements.
- https://github.com/mockito/mockito/releases/tag/v5.23.0
- https://github.com/mockito/mockito/releases/tag/v5.22.0
  - mockito/mockito#3778
  - mockito/mockito#3785
- https://github.com/mockito/mockito/releases/tag/v5.21.0
  - mockito/mockito#3758
- https://github.com/mockito/mockito/releases/tag/v5.20.0
  - mockito/mockito#3708
- https://github.com/mockito/mockito/releases/tag/v5.19.0
  - mockito/mockito#3659
- https://github.com/mockito/mockito/releases/tag/v5.18.0
- https://github.com/mockito/mockito/releases/tag/v5.17.0
- https://github.com/mockito/mockito/releases/tag/v5.16.0
- https://github.com/mockito/mockito/releases/tag/v5.15.0
  - mockito/mockito#3476
- https://github.com/mockito/mockito/releases/tag/v5.14.0
- https://github.com/mockito/mockito/releases/tag/v5.13.0

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (claude-opus-4-6)

Closes apache#54915 from dongjoon-hyun/SPARK-56098.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
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.

Static mocking of UUID.class corrupted under JDK 25

5 participants