Search code examples
javaintellij-ideanullablelombok

IntelliJ with Lombok with RequiredArgsConstructor and `private final` shows a unknown nullability warning


For the following dummy-like class

@Service
@RequiredArgsConstructor
public class SomeService
{
   private final AnotherService anotherService;
   private final ThirdService thirdService;

   public void doSomething(@NonNull final String subject)
   {
      if (this.anotherService.someMethod().isPresent())
      {
         this.thirdService.doThird(subject);
      }
   }
}

IntelliJ warns that

Warning: Method invocation 'someMethod' may produce 'NullPointerException' (unknown nullability)

despite the service being created by spring autowiring due to the @Service and @RequiredArgsConstructor tags. Is there a way to correctly fix this ?


Solution

  • Fixed but not included in the new stable releases https://youtrack.jetbrains.com/issue/IDEA-334216/IntelliJ-falsly-marks-as-Project-Error-when-using-Jakarta-Nonnull-annotation-in-combination-with-Lombok-RequiredArgsConstructor