Modify

Ticket #110 (closed defect: fixed)

Opened 11 years ago

Full qualified access is impossible for anonymous inner-classes

Reported by: Bernhard Haumacher (haui at haumacher dot de) Owned by:
Priority: normal Milestone: 1.05c
Component: JP trafo Version:
Severity: normal Keywords:
Cc:

Description

In the following code, the access to the variable 'norm' in generated code is wrong. The compiler crashes.

interface I {
  public int eval(int x);
}
class A {
  public static int foo() {
    final I f = new I() {
         int norm = Math.min(2, 3);
         public int eval(int x) {
           return norm * x;
         }
    };
    return f.eval(13);
  }
}

Evaluation

The compiler tries to generate a fully qualified access to the variable 'norm' of the form 'jp.test.TestInnerVar.foo..this.norm'. Because the inner class is anonymous, there is no such fully qualified access to 'norm'. The access should be transformed to 'this.norm'.

Solution

Use no reference to variables of anonymous inner classes at all.

See also

ticket:63

Test

jp.test.TestInnerVar

fixed since 1.05c.

Attachments

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.