Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 468122

Summary: [1.8][compiler] Passing interface extending package private functional interface into consuming function causes compiler error
Product: [Eclipse Project] JDT Reporter: Karsten Gregorius <distant.calls>
Component: CoreAssignee: Sasikanth Bharadwaj <sasikanth.bharadwaj>
Status: CLOSED DUPLICATE QA Contact: Stephan Herrmann <stephan.herrmann>
Severity: normal    
Priority: P3 CC: manoj.palat, stephan.herrmann
Version: 4.5   
Target Milestone: 4.6 M4   
Hardware: PC   
OS: Linux   
Whiteboard: To be verified for 4.7 RC3

Description Karsten Gregorius CLA 2015-05-24 05:06:36 EDT
Assume a package a.b with a package private functional interface a.b.I and another public interface extending I:

----- a.b.I -----
package a.b;

interface I {
  String doSomething();
}
----- a.b.I -----


----- a.b.Other -----
package a.b;

public interface Other extends I {
}
----- a.b.Other -----


When passing Other to any consuming function in a class outside a.b, this raises a compiler error:

----- a.b.c.SomeClient -----
package a.b.c;

import a.b.Other;

public class SomeClient {

  public static String execute() {
    /*
     * "The type I from the descriptor computed for the target context is not visible here." (and others)
     */
    return execute(() -> "fail");
  }

  private static String execute(Other o) {
    return o.doSomething();
  }
	
}
----- a.b.c.SomeClient -----


I'd expect ECJ to compile the above code without errors - at least, Java 1.8 does.

Seen in Eclipse 4.5M7 and RC1 (20150521-1252).
Comment 1 Stephan Herrmann CLA 2015-05-24 08:22:28 EDT
Indeed, javac accepts.

Using ecj HEAD I see exactly one error:

----------
1. ERROR in /tmp/a/b/c/SomeClient.java (at line 11)
        return execute(() -> "fail");
                       ^^^^^^^^^^^^
The type I from the descriptor computed for the target context is not visible here.  
----------                                                                                                   
What other errors do you see?

We report this error since bug 439707. My guess is, that the new check from that bug should use the target type, not the declaring class of the descriptor method.

Looking at JLS 15.27.3, which is what we implement in FE#kosherDescriptor() and which produces the error, I don't see any reason to complain against the declaring type. OTOH, I haven't yet found a JLS section that specifies the situation in bug 439707, so we may be left to our own reasoning.
Comment 2 Karsten Gregorius CLA 2015-05-24 09:11:43 EDT
Hm forget about that "and others" - the mentioned bug is the only one I actually saw. Those "others" went away after I had issued a clean on the project.
Comment 3 Stephan Herrmann CLA 2015-05-24 09:36:50 EDT
(In reply to Karsten Gregorius from comment #2)
> Hm forget about that "and others" - the mentioned bug is the only one I
> actually saw. Those "others" went away after I had issued a clean on the
> project.

thanks for clarifying.
Comment 4 Sasikanth Bharadwaj CLA 2016-08-24 07:10:58 EDT
Works as expected on master. Yet to find the change that fixed this
Comment 5 Stephan Herrmann CLA 2017-05-25 17:08:58 EDT

*** This bug has been marked as a duplicate of bug 478533 ***