Summary: | Difference seeing local class in switch with javac 1.4.2 | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Jerome Lanneluc <jerome_lanneluc> |
Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
Status: | RESOLVED WONTFIX | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 2.1 | ||
Target Milestone: | 3.0 M4 | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Whiteboard: |
Description
Jerome Lanneluc
2003-09-11 11:55:58 EDT
jikes 1.18 also accepts this code. 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)? See: http://developer.java.sun.com/developer/bugParade/bugs/4717190.html http://developer.java.sun.com/developer/bugParade/bugs/4725650.html http://developer.java.sun.com/developer/bugParade/bugs/4695057.html 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. |