Bug 400710

Summary: [1.8][compiler] synthetic access to default method generates wrong code
Product: [Eclipse Project] JDT Reporter: Stephan Herrmann <stephan.herrmann>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana
Version: 4.3   
Target Milestone: BETA J8   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 380501    
Attachments:
Description Flags
tentative fix none

Description Stephan Herrmann CLA 2013-02-13 11:13:43 EST
The following code generates wrong code:

interface I {
    public void foo() default {
        System.out.println("default");
    }
}
public class C implements I {
    public static void main(String[] args) {
        C c = new C();
        c.foo();
    }
}

At runtime this produces:
Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Object.foo()V
	at C.foo(C.java:1)
	at C.main(C.java:9)

The reason is in the way a synthetic method (SuperMethodAccess) for foo is generated: it is assumed that the super method must be in accessMethod.declaringClass.superclass(), which leads to trying to invoke java.lang.Object.foo(), which obviously doesn't exist.
Comment 1 Stephan Herrmann CLA 2013-02-13 11:26:00 EST
Created attachment 227029 [details]
tentative fix

This patch fixes the immediate issue but is not sufficiently tested.
Comment 2 Stephan Herrmann CLA 2013-02-15 05:46:17 EST
Jay, does my patch help for your test re static methods in interfaces?
Should I test and release this one first, or wait for you?
Comment 3 Stephan Herrmann CLA 2013-02-16 05:04:45 EST
If released the immediate patch via commit c22ae4e2acd996824ff94a2b0edaa0df69d9b3b1

Further cross-checking deferred to bug 391376.
Comment 4 Jay Arthanareeswaran CLA 2013-02-18 04:20:38 EST
(In reply to comment #2)
> Jay, does my patch help for your test re static methods in interfaces?
> Should I test and release this one first, or wait for you?

Yes, Stephan. Thank you!