This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 242435

Summary: "The assigned value is never used" after "if (true) return;" statement
Product: java Reporter: kris001
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: P3    
Version: 8.0   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:
Bug Depends on:    
Bug Blocks: 249320    
Attachments: Screen shot

Description kris001 2014-02-27 23:05:11 UTC
Created attachment 145648 [details]
Screen shot

Following an "if (true) return;" statement, all following assignments get "Unused Assignment" warnings rather than some sort of error about unreachable code 

This is not the case when there is a corresponding else, or the if condition is not trivial 


String test() {
	if (true) {
		return null;
	}
	String s = "foo";
	return s;
}
String test2() {
	if (true) {
		return null;
	} else {}
	String s = "foo";
	return s;
}

String test3() {
	if (1 == 1) {
		return null;
	}
	String s = "foo";
	return s;
}
Comment 1 Svata Dedic 2015-09-10 14:19:46 UTC
Caused by an optimization in the current implementation of flow analysis. I would rather join the fix with reimplementation of the flow/npe check.
Comment 2 Martin Balin 2016-07-07 07:16:14 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss