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

Bug 577181

Summary: Pattern Matching for instanceof and @NonNullByDefault
Product: [Eclipse Project] JDT Reporter: Holger Kanwischer <holger.kanwischer>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 4.22   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:

Description Holger Kanwischer CLA 2021-11-10 07:27:00 EST
Annotation-bases null analysis is enabled.

import org.eclipse.jdt.annotation.NonNullByDefault;

@NonNullByDefault
public class NonNullByDefaultAndInstanceof {

	void test2(Object o) {
		if (o instanceof Long l) {
			test2(l); //<<<
		}
	}

	void test2(Long l) {
		System.out.println(l);
	}
}

The following invalid warning is issued for the line marked with "<<<":
Null type safety (type annotations): The expression of type 'Long' needs unchecked conversion to conform to '@NonNull Long'
Comment 1 Stephan Herrmann CLA 2021-12-06 07:14:27 EST

*** This bug has been marked as a duplicate of bug 571933 ***