Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 571933

Summary: Unnecessary null type safety warning for instanceof variable used as method call parameter
Product: [Eclipse Project] JDT Reporter: Sergey Orlov <sergey.i.orlov>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED MOVED QA Contact:
Severity: normal    
Priority: P3 CC: holger.kanwischer, stephan.herrmann
Version: 4.18   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Attachments:
Description Flags
Test project none

Description Sergey Orlov CLA 2021-03-13 04:51:09 EST
Created attachment 285831 [details]
Test project

package test;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

final class Test
{
  private static final void accept(@Nullable Object o)
  {
    if (o instanceof Test test)
    {
      accept(test); // <== Null type safety (type annotations): The expression of type 'Test' needs unchecked conversion to conform to '@NonNull Test'
    }
  }

  private static final void accept(@NonNull Test test)
  {
    System.out.println(test);
  }

  public static final void main(String[] arguments)
  {
    accept((Object) null);
  }
}
Comment 1 Stephan Herrmann CLA 2021-12-06 07:14:27 EST
*** Bug 577181 has been marked as a duplicate of this bug. ***
Comment 2 Stephan Herrmann CLA 2022-08-26 16:50:52 EDT
Let's continue in https://github.com/eclipse-jdt/eclipse.jdt.core/issues/350