Bug 438923 - [compiler] nested type is inappropriately considered "indirectly referenced"
Summary: [compiler] nested type is inappropriately considered "indirectly referenced"
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: 4.4.2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords: greatbug
: 448922 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-07-04 07:21 EDT by Rune Glerup CLA
Modified: 2015-01-20 03:27 EST (History)
10 users (show)

See Also:


Attachments
Patch: 4.4.2 (4.56 KB, patch)
2014-10-08 00:24 EDT, shankha banerjee CLA
shankhba: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rune Glerup CLA 2014-07-04 07:21:08 EDT
In Eclipse 4.4, a possible compiler bug affects our codebase.

The trigger conditions seems to be (every class is declared in an exported packaged named the same as the bundle):

 1. In bundle org.example.a:
    a. Declare an interface A
    b. Declare a nested interface A.Inner

 2. In bundle org.example.b:
    a. Import package org.example.a
    b. Declare a class B
    c. Use the type A.Inner as a type parameter in a private method return type or argument, e.g. Iterable<A.Inner>

 3. In bundle org.example.c:
    a. Import package org.example.b
    b. Call a function in class B

Expected behavior:
Since the type A.Inner is not exposed in the public interface of the class B, it should not be necessary to import org.example.a to use B.

Actual behavior:
Compiler error: The type org.example.a.A$Inner cannot be resolved. It is indirectly referenced from required .class files

I have created a small project that illustrates this problem: https://github.com/glerup/eclipse-pde-indirectly-referenced-bug
Comment 1 kurt CLA 2014-07-07 07:35:45 EDT
This applies also for "normal" Java-Projects.
Following "setup" works fine in Eclipse 4.3.2:

Project 1:
package p1;
public interface P1I0 {
  interface II {/*empty*/}
}

Project 2 - has Project 1 on classpath:
package p2;
import p1.P1I0;
public class P2C0 {
  public void z(final P1I0.II... ii) {/*empty*/}
}

Project 3 - has Project 2 on classpath:
package p3;
import p2.P2C0;
public class P3C0
  extends P2C0 {/*empty*/}

My findings:

Visibility of method z does not matter.
When changing z's parameter to a simple paramater, no compile errors.
So it looks like the Type-Parameter "resolution" is the problematic peace of code in the Eclipse-Compiler.

As we have a lot of projects, which would have to change classpath-settings,
I would like to see the "Importance" of that bug to be at a higher level.
Comment 2 Curtis Windatt CLA 2014-07-08 10:11:29 EDT
I haven't gone through the example in detail, but this sounds like another duplicate of bug 73957.
Comment 3 Rune Glerup CLA 2014-07-08 10:39:37 EDT
(In reply to Curtis Windatt from comment #2)
> I haven't gone through the example in detail, but this sounds like another
> duplicate of bug 73957.

While the error message is the same, this particular problem is new in Eclipse 4.4. The reproduction scenario compiles in Eclipse 4.3, but yields a compilation error in Eclipse 4.4.

The "indirectly referenced" compilation error usually appears when a type from a bundle dependency in its interface references a type from a transitive dependency. In these cases it is necessary to also import/require the transitive dependency.

But in this case, the compilation error occurs even when the type is only used in a private method and is not exposed in the interface in any way, which I think is very problematic.

Triggering this does require some rather specific conditions (which happened to be fulfilled in 9 places in our codebase):

 1. The transitive dependency needs to be a nested type
 2. The nested type must be used as a type argument (e.g. Iterable<I.Nested>) or in a varargs position (e.g. I.Nested...)

Try playing around with the very simple reproduction scenario on GitHub and let me know what you think.

Based on Kurt's comment #1 this may be a JDT problem since it also seem to affect non-OSGi Java projects.
Comment 4 Curtis Windatt CLA 2014-07-08 17:21:30 EDT
I will mark for investigation in 4.5, but I don't have time to look at this in detail currently.  I'm also moving it to PDE UI (where we handle the project dependencies) as well as marking it as a greatbug with clear steps to reproduce and an example project.
Comment 5 Curtis Windatt CLA 2014-07-08 17:24:51 EDT
(In reply to Rune Glerup from comment #3)
> Based on Kurt's comment #1 this may be a JDT problem since it also seem to
> affect non-OSGi Java projects.

I'll move to JDT for comment.  PDE adds the dependencies to the JDT classpath, so this bug may originate there.
Comment 6 Jay Arthanareeswaran CLA 2014-07-08 23:49:08 EDT
This sounds familiar, but I can't dig out the relevant bug. 

Srikanth, any idea?
Comment 7 Srikanth Sankaran CLA 2014-09-02 04:07:32 EDT
Hello Rune, are you able to attach an example project to bugzilla here that 
I can simply import to observe the problem. I appreciate that you have taken
the effort to stage the test case in github, but a simple importable project
attached to bugzilla would work best for me. Thanks.
Comment 8 Srikanth Sankaran CLA 2014-09-02 04:10:46 EDT
Sorry for the noise, my team mate showed me how to get what I wanted right
from github. Thanks.
Comment 9 Srikanth Sankaran CLA 2014-09-02 04:40:33 EDT
Looks like a regression brought about by the fix for bug 423849
Comment 10 Srikanth Sankaran CLA 2014-09-02 05:42:30 EDT
Fix and test released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=c00079358eb2e0feded1f86b5088b09215957a9d

The fix for was calling for overeager resolution of nested types. We now have
built in some tolerance for missing types when evaluated eagerly.
Comment 11 shankha banerjee CLA 2014-09-16 09:29:34 EDT
Verified for Mars 4.5M2 using I20140915-2000 build.
Comment 12 Randy Hudson CLA 2014-10-01 14:20:11 EDT
I am seeing a problem that looks like this bug.  The difference is, in 2.c., A.Inner is used as a parameter in a public method.  Also for step 3, all I need to do is import the type (not the whole package) org.example.b.B.  The error appears without using B anywhere in C.

I have several projects with compile errors in 4.4 due to this bug.  Can this be back ported?
Comment 13 Markus Keller CLA 2014-10-01 14:25:45 EDT
I agree this looks severe enough for backporting to 4.4.2, and the fix doesn't look too complicated.

Rune / Kurt, did you have a chance to test the fix in 4.5 M2 to verify that it fixes all your real-life cases?
Comment 14 kurt CLA 2014-10-02 04:00:38 EDT
Since we had to change to 4.4 we fixed the classpaths for the projects.
The only fast check I could do, would be the testcase I provided.
Comment 15 kurt CLA 2014-10-02 05:10:29 EDT
Could check with
  Version: Mars (4.5)
  Build id: I20140918-0330
.

Luckily I had a "backup" of the workspace, so I could check real-life-case also.

Both compile without errors again (compiler-compliance level 1.6, after clean-build).

Would be nice to see that backported to 4.4.

Thanks
Kurt
Comment 16 Markus Keller CLA 2014-10-02 11:30:10 EDT
Reopening for back port.
Comment 17 Rune Glerup CLA 2014-10-02 13:55:23 EDT
(In reply to Markus Keller from comment #13)
> Rune / Kurt, did you have a chance to test the fix in 4.5 M2 to verify that
> it fixes all your real-life cases?

Our real-life cases compile without errors in the 4.5 M2 build.
Comment 18 Srikanth Sankaran CLA 2014-10-07 20:56:02 EDT
Shankha, can you please backport this ? TIA.
Comment 19 shankha banerjee CLA 2014-10-08 00:24:35 EDT
Created attachment 247701 [details]
Patch: 4.4.2
Comment 20 shankha banerjee CLA 2014-10-08 00:25:33 EDT
(In reply to shankha banerjee from comment #19)
> Created attachment 247701 [details]
> Patch: 4.4.2

Hi Srikanth,
Can you please review.

Thanks
Comment 21 shankha banerjee CLA 2014-10-08 05:20:01 EDT
Backported on R4_4_maintenance 

Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=b1ad3a9c0fed9f836b3039d8ebc5cb946105230a.

Thanks
Comment 22 shankha banerjee CLA 2014-10-08 05:22:56 EDT
Patch Ported to R4_4_maintenance.
Comment 23 shankha banerjee CLA 2014-10-08 05:23:55 EDT
Patch ported to R4_4_maintenance.
Comment 24 Frank Neblung CLA 2014-10-27 07:41:21 EDT
*** Bug 448922 has been marked as a duplicate of this bug. ***
Comment 25 shankha banerjee CLA 2015-01-20 03:27:35 EST
Verified for 4.4.2 RC1 using build M20150114-1500.