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

Bug 561506

Summary: [1.8][null] flow analysis of ternary is tricked by @NonNull Long input type
Product: [Eclipse Project] JDT Reporter: Stephan Herrmann <stephan.herrmann>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 4.16   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Stephan Herrmann CLA 2020-03-26 19:04:14 EDT
Given this program:
//---
package bugs;
import org.eclipse.jdt.annotation.NonNull;

public class LongInTernary {
	void withoutNullLong(@NonNull Long id, boolean b) {
		System.out.println(id.intValue());
	    withoutNullLong(b ? id : null, b);
	}
	void withoutNullString(@NonNull String id, boolean b) {
		System.out.println(id.toUpperCase());
	    withoutNullString(b ? id : null, b);
	}
	public static void main(String[] args) {
		new LongInTernary().withoutNullLong(31L, false);
	}
}
//---

the compiler flags an error on the recursive call within withoutNullString() but has no complaints against withoutNullLong().

When run, the program produces:

31
Exception in thread "main" java.lang.NullPointerException
	at bugs.LongInTernary.withoutNullLong(LongInTernary.java:7)
	at bugs.LongInTernary.withoutNullLong(LongInTernary.java:8)
	at bugs.LongInTernary.main(LongInTernary.java:21)

Is some auto-un-boxing happening behind the scenes that confuses the analysis??