Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 2.5.12
-
Component/s: None
-
Labels:None
-
Environment:Ms Windows XP SP2, JDK1.5u11
-
Testcase included:yes
-
Number of attachments :
Description
A class has a inner class definition, and immediately after that an instance of this inner class is created:
public class Code { class Price { public int getPriceA() { return 1; } public int getPriceB() { return 2; } } // create an instance of the inner class Price price; ...
Then, in the same enclosing class, in one of the methods, a call to a member method of the inner class instance is made:
...
public int assign() {
// this should not compile
return price.Rate();
}
int Rate () {
return 17;
}
}
However, the method called (Rate) is not in the inner class definition, it is one of the methods that exist in the enclosing, outer type. This bug makes it possible to call a method of an enclosing type as if it was defined for the inner type, when invoked on an instance in the inner type within the outer type. If my explanation is messy please see the file attached (code.txt). The attached code doesn't compile using the JDK javac tool.
The problem was noticed when woking with ClassBodyEvaluator, but SimpleCompiler works exactly the same (the only difference is that class CBE doesn't use the enclosing class declaration - see the test case in the attached JaninoTest.java file).
Sorry, I forgot to add that I tested this against version 2.5.0, as well as the latest 2.5.11.