Janino

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Critical 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 :
    2

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).

  1. code.txt
    14/Nov/07 11:24 AM
    0.4 kB
    Bernard Smith
  2. JaninoTest.java
    14/Nov/07 11:24 AM
    2 kB
    Bernard Smith

Activity

Hide
Bernard Smith added a comment -

Sorry, I forgot to add that I tested this against version 2.5.0, as well as the latest 2.5.11.

Show
Bernard Smith added a comment - Sorry, I forgot to add that I tested this against version 2.5.0, as well as the latest 2.5.11.
Hide
Arno Unkrig added a comment -

Thank you for the test case; included it in "ReportedBugs.java".

Show
Arno Unkrig added a comment - Thank you for the test case; included it in "ReportedBugs.java".

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: