question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException when using argThat() for long parameter in verify

See original GitHub issue

A minimal code example:

  @Test
  public void shouldNotBeBroken() throws Exception {
    TakesALong takesALong = mock(TakesALong.class);

    verify(takesALong).call(argThat(CoreMatchers.equalTo(11L)));
  }

  static interface TakesALong {
    void call(long l);
  }

This leads to an NPE logged as happening at the ‘verify’ call, which made me think that the the result of verify(takesALong) was null, but it seems like the NPE has a somewhat incomplete stack trace. Variations that don’t show this problem include:

  • changing the interface to take a Long instead of a long, or
  • using longThat(Matcher<Long>) instead of argThat()

If it is considered an error to use argThat where you’re passing in a long, then I think at least there should be a better error message.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
mockitoguycommented, Nov 15, 2014

I agree that better error message would be great. Do you have suggestions how to implement it?

There’s a ‘longThat’ method that can be used in this context.

Hope that helps!

0reactions
bric3commented, Aug 17, 2016

Again, something against Eclipse. It’s not the first bad bug using Eclipse compiler.

– Brice

On Wed, Aug 17, 2016 at 12:39 PM +0200, “Christian Schwarz” notifications@github.com wrote:

Jup!

It’s a bug in eclipse JDT that only occures with a non standard JRE execution environment and compiler compliance setup. I filed an issue for the JDT-Team: Bug 499817

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException when working with ArgumentMatcher
You have a NullPointerException because the method signature is using a native type, and you are using Matchers.argThat , which returns an ...
Read more >
NullPointerException using two given with argThat on same ...
Hi people, I have a classe that use a Dao's method that receive a List as parameter. I need two diffent responses depend...
Read more >
ArgumentMatchers (Mockito 3.8.0 API) - Javadoc.io
If you are using argument matchers, all arguments have to be provided by matchers. E.g: (example shows verification but the same applies to...
Read more >
MockitoHamcrest (Mockito 3.9.0 API) - Javadoc
Allows matching arguments with hamcrest matchers. ... Note the NullPointerException auto-unboxing caveat described ... MockitoHamcrest() ...
Read more >
A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Unit tests are designed to test the behavior of specific classes or methods ... Here we create the hasLuck argument matcher and use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found