Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348379 - [1.7][compiler] Null pointer access warning for strings in switch
Summary: [1.7][compiler] Null pointer access warning for strings in switch
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.7.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-06 07:25 EDT by Deepak Azad CLA
Modified: 2011-08-05 02:54 EDT (History)
4 users (show)

See Also:


Attachments
proposed fix v1.0 + regression tests (6.93 KB, patch)
2011-06-06 12:06 EDT, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2011-06-06 07:25:29 EDT
The compiler should show a warning on switch(s).
--------------------------------------------------------------
	void foo() {
		String s = null;
		switch (s) {  // should be a warning here
		case "abcd":
			System.out.println("abcd");
			break;
		case "xyz":
			System.out.println("xyz");
			break;
		default:
			System.out.println("oops");
			break;
		}
	}
--------------------------------------------------------------
Comment 1 Ayushman Jain CLA 2011-06-06 07:41:05 EDT
This is the only case in which strings can cause an NPE. So needs to be included in null analysis.
Comment 2 Ayushman Jain CLA 2011-06-06 12:06:13 EDT
Created attachment 197414 [details]
proposed fix v1.0 + regression tests
Comment 3 Ayushman Jain CLA 2011-06-06 12:09:51 EDT
Released in BETA_JAVA7 branch.
Comment 4 Srikanth Sankaran CLA 2011-06-28 04:53:24 EDT
Verified using "Eclipse Java Development Tools Patch for Java 7 Support (BETA)	1.0.0.v20110623-0900	org.eclipse.jdt.patch.feature.group	Eclipse.org"