'Mockito notNull required for inferred annotation

I'm struggling to stub a method where IntelliJ creates an inferred annotation not null on the parameter:

 public final boolean isGlobalMatchCriteria(GlobalStore global) {
        return global.getMessage() != null );
    }

i tried to stub it this way, i also tried to replace notNull with more accurate any() :

when(manager.isGlobalMatchCriteria(notNull())).thenReturn(true);

Where manager is a Component that i mock.

@MockBean
 GlobalStoreManager manager;

I keep having this error :

java.lang.NullPointerException: Cannot invoke "xxx.store.GlobalStore.getMessage()" because "global" is null

I don't understand why is it blocking on this potential null. I even called :

Objects.requireNonNull(global);

But it doesn't pass the stubbing. The execution stops on the when().thenReturn() method.

I don't get what's going on here.

Edit : changed the name of the manager for clarity.



Solution 1:[1]

The method is final... And stubbing doesn't work on final method. As it's code legacy and i don't know why it's final... I deleted the final XD And it works like a charm.

Edit : I really struggled on this one as the Mockito error was really misleading.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Coshi