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

Bug 348379

Summary: [1.7][compiler] Null pointer access warning for strings in switch
Product: [Eclipse Project] JDT Reporter: Deepak Azad <deepakazad>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: amj87.iitr, daniel_megert, deepakazad, srikanth_sankaran
Version: 3.7   
Target Milestone: 3.7.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
proposed fix v1.0 + regression tests none

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"