Bug 400710 - [1.8][compiler] synthetic access to default method generates wrong code
Summary: [1.8][compiler] synthetic access to default method generates wrong code
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 380501
  Show dependency tree
 
Reported: 2013-02-13 11:13 EST by Stephan Herrmann CLA
Modified: 2013-02-18 04:20 EST (History)
1 user (show)

See Also:


Attachments
tentative fix (2.38 KB, patch)
2013-02-13 11:26 EST, Stephan Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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!