Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixes #3237: Fix NullPointerException in Only.verify #3349

Merged

Conversation

baezzys
Copy link
Contributor

@baezzys baezzys commented May 19, 2024

Motivation

In the latest version of mockito-core (5.9.0), the Only.verify method throws a NullPointerException when it attempts to call Reporter.noMoreInteractionsWanted with a null argument. This occurs because the method InvocationsFinder.findFirstUnverified can return null, but this is not handled properly in Only.verify.

This fixes #3237

Changes

  • Added a null check for the result of InvocationsFinder.findFirstUnverified in Only.verify. If the result is null, Reporter.noMoreInteractionsWanted is not called.

Checklist

  • [v] Read the contributing guide
  • [v] PR should be motivated, i.e. what does it fix, why, and if relevant how
  • [v] If possible / relevant include an example in the description, that could help all readers
    including project members to get a better picture of the change
  • [v] Avoid other runtime dependencies
  • [v] Meaningful commit history ; intention is important please rebase your commit history so that each
    commit is meaningful and help the people that will explore a change in 2 years
  • [v] The pull request follows coding style
  • [v] Mention Fixes #<issue number> in the description if relevant
  • [v] At least one commit should mention Fixes #<issue number> if relevant

@baezzys baezzys force-pushed the fix/only-verify-nullpointerexception branch 2 times, most recently from 059f448 to c0184d8 Compare May 19, 2024 03:23
Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and regression test!

@codecov-commenter
Copy link

codecov-commenter commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.36%. Comparing base (c54e43b) to head (4dcd1b7).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #3349   +/-   ##
=========================================
  Coverage     85.35%   85.36%           
- Complexity     2926     2927    +1     
=========================================
  Files           336      336           
  Lines          8907     8908    +1     
  Branches       1109     1110    +1     
=========================================
+ Hits           7603     7604    +1     
  Misses         1013     1013           
  Partials        291      291           

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

…rified invocation

This resolves the issue where Only.verify throws a NullPointerException when no unverified invocations are found.
@baezzys baezzys force-pushed the fix/only-verify-nullpointerexception branch from c0184d8 to 4dcd1b7 Compare May 24, 2024 05:47
@TimvdLippe TimvdLippe merged commit 110a39b into mockito:main May 24, 2024
18 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Method Only.verify throws NullPointerException
3 participants