Community
Participate
Working Groups
Build ID: I20080617-2000 Steps To Reproduce: The Eclipse compiler incorrectly reports the field is defined in an inherited type and an enclosing scope when the JDK Compliance level is set to JDK 1.3. In the below code fragment, the eclipse java compiler will report "The field _state is defined in an inherited type and an enclosing scope". This error will disappear if the JDK Compliance level is set to 1.4 or above. Since compiling for CLDC requires a JDK 1.3 Compliance level target, This will be a continuous issue for any JavaME developers. public class ClassA { ClassB _state; public class ClassB { int _state; } public class ClassD extends ClassB { public void myMethod() { _state = 0; //This gives a compilation error //when compiler compliance level //is set to JDK 1.3 } }//end of ClassD }//end of ClassA More information: The JRE version I'm using is 1.5.0_14.
The compliance level (1.3) emulates the corresponding JDK level. If you feed javac 1.3.1 with your testcase, you will also get an error: ClassA.java:10: _state is inherited from ClassA.ClassB and hides variable in outer class ClassA. An explicit 'this' qualifier must be used to select the d esired instance. _state = 0; //This gives a compilation error ^ Basically, the language evolved between 1.3 and 1.4 to privilege inherited over enclosing. This explains why a Javac 1.5 would compile it clean. Same for Eclipse compiler, if you set compliance above 1.3. If you look closely to the compliance preference page, you can see that there are actually 3 settings: 1. compliance 2. source level 3. target level 1. emulates the corresponding JDK 2. is equivalent to option -source for javac 3. is equivalent to option -target for javac So if all you care is to have a target JRE <= 1.3, then you can use: 1. Compliance = 1.4 2. Source = 1.3 3. Target = 1.2 (which are the defaults when toggling the Compliance to 1.4, and keep default source/target levels).
Srikanth - pls add some regression test (FieldAccessTest) and close as invalid (since the expectation does not match the spec) The test should be using compliance check to set different expectation based on compliance level (e.g. LookupTest#test074)
(In reply to comment #2) > Srikanth - pls add some regression test (FieldAccessTest) and close as invalid > (since the expectation does not match the spec) > The test should be using compliance check to set different expectation based on > compliance level (e.g. LookupTest#test074) There are numerous tests that elicit this diagnostic. In particular, org.eclipse.jdt.core.tests.compiler.regression.SuperTypeTest.test002() org.eclipse.jdt.core.tests.compiler.regression.SuperTypeTest.test003() org.eclipse.jdt.core.tests.compiler.regression.SuperTypeTest.test004() seem to test both the negative test (1.3) and conform test (1.4, 1.4+). These tests look adequate to me. Did you have any additional scenarios in mind ?
Closing as Invalid for Srikanth Existing regression tests are sufficient
Verified for 3.5M6