Issue Details (XML | Word | Printable)

Key: JANINO-105
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Arno Unkrig
Reporter: Bernard Smith
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Janino

Possible to call a method of an enclosing class as if it was a member of an inner class

Created: 14/Nov/07 11:24 AM   Updated: 20/Dec/07 03:16 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.5.12

Time Tracking:
Not Specified

File Attachments: 1. Text File code.txt (0.4 kB)
2. Java Source File JaninoTest.java (2 kB)

Environment: Ms Windows XP SP2, JDK1.5u11

Testcase included: yes


 Description  « Hide
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).



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Bernard Smith added a comment - 15/Nov/07 03:36 AM
Sorry, I forgot to add that I tested this against version 2.5.0, as well as the latest 2.5.11.

Arno Unkrig added a comment - 20/Dec/07 03:16 PM
Thank you for the test case; included it in "ReportedBugs.java".