Bug 42960 - Difference seeing local class in switch with javac 1.4.2
Summary: Difference seeing local class in switch with javac 1.4.2
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-11 11:55 EDT by Jerome Lanneluc CLA
Modified: 2003-09-11 15:07 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerome Lanneluc CLA 2003-09-11 11:55:58 EDT
Build 20030910

The following class compiles fine with javac 1.4.1 and our compiler, but it 
fails with javac 1.4.2:

public class TestCaseSwitch {
	int i = 0;
	public TestCaseSwitch() {
		switch (i) {
			case 0 :
				class InCaseClass {
					public void print() {
						System.out.println("i=" + i);
					}
				}
				InCaseClass icc = new InCaseClass();
				icc.print();
				break;
			default :
				icc = new InCaseClass();
				icc.print();
				break;
		}
	}
	public static void main(String[] args) {
		TestCaseSwitch t = new TestCaseSwitch();
	}
}

The failure with javac 1.4.2 is:
TestCaseSwitch.java:15: cannot resolve symbol
symbol  : class InCaseClass
location: class TestCaseSwitch
                                icc = new InCaseClass();
                                          ^
1 error

Who is right? Need to check the spec.
Comment 1 Olivier Thomann CLA 2003-09-11 14:42:25 EDT
jikes 1.18 also accepts this code.
Comment 2 Olivier Thomann CLA 2003-09-11 14:46:03 EDT
javac 1.4.2 looks inconsistent.
If you change the code to:
public class TestCaseSwitch {
	int i = 0;
	public TestCaseSwitch() {
		switch (i) {
			case 0 :
				class InCaseClass {
					public void print() {
						System.out.println("i=" + i);
					}
				}
				Object icc = new InCaseClass();
				icc.toString();
				break;
			default :
				icc = new Object();
				icc.toString();
				break;
		}
	}
	public static void main(String[] args) {
		TestCaseSwitch t = new TestCaseSwitch();
	}
}
It compiles fine with javac 1.4.2.
If the inner class is not visible (first version of the code), why the local
variable icc would be visible (second version)?
Comment 4 Philipe Mulet CLA 2003-09-11 15:07:20 EDT
I remember javac 1.4.2 build notes mentionning something about solving a defect 
in this area. I had the impression they had solved a defect in flow analysis 
where the local type could be used in subsequent catch but captured variable 
wasn't initialized there. It seems they took a too drastic measure to disallow 
this.

Bug http://developer.java.sun.com/developer/bugParade/bugs/4725650.html
clearly shows they solved the flow analysis problem by reducing the scope, and 
introducing an inconsistency with local variables, in an area where the spec is 
vague. 

Jikes and us both agree, Javac is wrong.
Closing.