Miranda methods and Methods added by Code Generators

Andrew Dinn adinn at redhat.com
Fri Aug 6 08:21:07 PDT 2010

Dear Compiler Devs,

The JBoss AOP team recently ran in to a problem when transforming an 
abstract class offline (see https://jira.jboss.org/browse/JBAOP-731 for 
details). The AOP transform operation loads the bytecode for a class, 
call it X, manipulates it to insert, inter alia, a getAdvisor() method 
then rewrites the classfile. Method getAdvisor is SYNTHETIC and has a 
Code attribute. It is _NOT_ ABSTRACT.

When javac subsequently tries to compile the source for Y extends X it 
complains that Y does not implement getAdvisor(). It turns out that 
javac is assuming that the SYNTHETIC implementation found in the 
transformed classfile for X is a Miranda method even though it is not 
ABSTRACT. The relevant code is in method

com.sun.tools.javac.code.Types.implementation(MethodSymbol ms, 
TypeSymbol, Types, boolean)

The offending code is

1968    MethodSymbol impl = cache.get(origin);
. . .   if (impl == null) {
             for (Type t = origin.type; t.tag == CLASS || t.tag == 
TYPEVAR; t = types.supertype(t)) {
                 while (t.tag == TYPEVAR)
                     t = t.getUpperBound();
                 TypeSymbol c = t.tsym;
                 for (Scope.Entry e = c.members().lookup(ms.name);
                      e.scope != null;
                      e = e.next()) {
                     if (e.sym.kind == Kinds.MTH) {
                         MethodSymbol m = (MethodSymbol) e.sym;
                         if (m.overrides(ms, origin, types, checkResult) &&
                             (m.flags() & SYNTHETIC) == 0) {
                             impl = m;
                             cache.put(origin, m);
                             return impl;

My contention is that this is a bug. javac should only regard ABSTRACT 
SYNTHETIC methods as Miranda methods. After all, Miranda methods are all 
abstract are they not?

Is there some good reason why _ANY_ SYNTHETIC method has to be rejected? 
If not then the recommended patch would be to change the 'if' condition 
at line 1978/9 above to

                         if (m.overrides(ms, origin, types, checkResult) &&
                             (m.flags() & (SYNTHETIC|ABSTRACT)) != 


Andrew Dinn
Senior Software Engineer, JBoss
Red Hat UK Ltd
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod 
Street, Windsor, Berkshire,
SI4 1TE, United Kingdom.
Registered in UK and Wales under Company Registration No. 3798903
Directors: Michael Cunningham (USA), Charlie Peters (USA), Matt Parsons
(USA)  and Brendan Lane (Ireland)

More information about the compiler-dev mailing list