Skip to content

withCapture() replaces captured nulls with default values for wrapper types #617

@rmichalak

Description

@rmichalak
  • Version of JMockit that was used: 1.46

  • Description of the problem or enhancement request:

When this test is executed:

public final class WithCaptureTest
{
   @Test
   public void captureNullToLocalVariable() {
      dao.doSomething((Integer)null);

      new Verifications() {{
         Integer i;
         dao.doSomething(i = withCapture());
         assertNull(i);
      }};
   }
}

i is assigned with 0 value instead of null.
I tracked this down to this line: mockit/internal/expectations/ActiveInvocations.java:96
and it seems like it was introduced as a fix for NPE for "certain misuses of the argument matching/capturing". Is it an intended behavior?

Workaround would be to use withCapture(List) which seems to handle null values properly (#567)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions