Bug 305259 - Strange error when referencing code produced with jsr14 target
Summary: Strange error when referencing code produced with jsr14 target
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux
: P5 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 179195 318573 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-03-09 17:53 EST by Ian Bull CLA
Modified: 2010-11-02 18:15 EDT (History)
9 users (show)

See Also:
frederic_fusier: review+


Attachments
Screenshot showing the problem (124.66 KB, image/png)
2010-03-09 17:53 EST, Ian Bull CLA
no flags Details
Test projects (170.52 KB, application/octet-stream)
2010-06-10 13:19 EDT, Thomas Watson CLA
no flags Details
Patch under consideration. (2.61 KB, patch)
2010-08-17 04:20 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch under test (13.06 KB, patch)
2010-08-18 10:11 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Proposed patch (13.06 KB, patch)
2010-08-18 11:30 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Bull CLA 2010-03-09 17:53:02 EST
Created attachment 161546 [details]
Screenshot showing the problem

In p2 we have generated our .class files with the jsr14 target.  However, if we use some of these classes (from code which is set to 1.4 source / target), we get strange errors.  The errors are strange because they do not show up in the compile error view, nor do they show up as markers on the file itself. However, if you look in the .java file, you see a marker.

The particular error is:

The method toArray(Class) from the type IQueryResult refers to the missing type T

I've attached a screenshot to show you what I mean.
Comment 1 Olivier Thomann CLA 2010-03-09 18:00:33 EST
> In p2 we have generated our .class files with the jsr14 target.  However, if we
> use some of these classes (from code which is set to 1.4 source / target), we
> get strange errors.  The errors are strange because they do not show up in the
> compile error view, nor do they show up as markers on the file itself. However,
> if you look in the .java file, you see a marker.
This is not a marker, but rather a wrong highlighting.

The problem comes from the reconciler. I'll what I can do to fix this case, but since this is not a supported target, it is not a high priority.
Comment 2 Ian Bull CLA 2010-03-09 18:06:15 EST
> The problem comes from the reconciler. I'll what I can do to fix this case, but
> since this is not a supported target, it is not a high priority.

Re: not a supported target, that may explain my other bug (bug 305255) :-)

No rush, I just wanted to log these bugs so they didn't get lost.  However, now that p2 is using this target, is there something we can do to make it supported target (obviously not for 3.6)?
Comment 3 Pascal Rapicault CLA 2010-03-10 12:48:14 EST
Ian, when we started using this feature in p2, there was a tacit agreement
between Olivier and I (and even discussed during the eclipse team meeting) that
we would not ask to make that support full fledged because this could require a
lot of work and would not be useful to a majority of ppl (like support for Java
7 would).
Comment 4 Dani Megert CLA 2010-03-16 12:55:29 EDT
We can keep the bug open but currently there are no plans to invest into jsr14
target.
Comment 5 Thomas Watson CLA 2010-06-10 13:19:26 EDT
Created attachment 171656 [details]
Test projects

I don't think this has anything to do with jsr14.  Attached are two plain old Java projects that show the issue without the use of jsr14.  The key is the client (where the error is) is using compile setting of J2SE-1.4 and compiling against another project that is using the compile settings of Java 5 and has generics in the API.
Comment 6 Olivier Thomann CLA 2010-06-10 14:32:33 EDT
As far as I know this is only a reconciler issue. I'll debug it. It is not directly related to jsr14, but it is related to the fact that 1.5 API are referenced inside a project set as 1.4. So this is the kind of settings that you get a lot when using the jsr14.
If you disable the report of problem as you type, the error is gone.

I'll investigate it.
Comment 7 Olivier Thomann CLA 2010-06-11 11:37:56 EDT
This is why we have a problem.
In the reconciler, the BundleContext unit is retrieved as a source type, but it is "read" with the compiler options from the caller site (1.4). So all its 1.5 information is lost and when the getService() method is resolved, its return type name is S. It is resolved as a 1.4 method with a return type S that is not found.
During the compilation, the type is retrieved as a binary type that preserves all its generic information.
So the way to fix this would be to retrieve dependent types using their own compiler options. I'll make some experiment in this direction.
Comment 8 Olivier Thomann CLA 2010-06-11 12:11:54 EDT
In order to fix this, we would need to store the compiler options of each unit inside its compilation scope. Right now the scope gets the global options from the lookup environment which doesn't work well when some types should be read using 1.4 level and some types should be read using 1.5 level.
This is an issue only with source types.
Comment 9 Olivier Thomann CLA 2010-07-01 09:28:13 EDT
*** Bug 318573 has been marked as a duplicate of this bug. ***
Comment 10 Thomas Watson CLA 2010-08-06 15:34:46 EDT
This bug is going to cause a bit of grief when the patch in bug 322007 is released.  The OSGi APIs will have generics.  Any project using J2SE 1.4 project settings will see these strange errors in their editor for calls to the OSGi API that has generics.

This appears to only be an issue if the project containing generics in their API is in the workspace, so perhaps it is not as big of an issue.  To me it is rather annoying because I ALWAYS have org.eclipse.osgi in my workspace ;-)
Comment 11 Srikanth Sankaran CLA 2010-08-11 07:17:14 EDT
Olivier is away all of this month, I'll take a look
and see what is involved.
Comment 12 Srikanth Sankaran CLA 2010-08-17 00:57:07 EDT
(In reply to comment #7)

> During the compilation, the type is retrieved as a binary type that preserves
> all its generic information.

The type is retrieved as a binary type where all the generic information
is erased. So instead of attempting to resolve a return type of S where
S is a type variable, we attempt to resolve java.lang.Object and we have
nothing to complain about.
Comment 13 Srikanth Sankaran CLA 2010-08-17 04:20:57 EDT
Created attachment 176764 [details]
Patch under consideration.
Comment 14 Srikanth Sankaran CLA 2010-08-17 05:38:26 EDT
All JDT/Core tests pass, I'll add a regression test and test
some more. 

Ian, Thomas:

Are you in a position to apply the source patch (3.7 HEAD) and
test ? TIA.
Comment 15 Thomas Watson CLA 2010-08-17 09:38:24 EDT
(In reply to comment #14)
> Ian, Thomas:
> 
> Are you in a position to apply the source patch (3.7 HEAD) and
> test ? TIA.

Yes, and it seems to have fixed up the errors I was seeing in the Java editor.  Thanks.
Comment 16 Srikanth Sankaran CLA 2010-08-18 05:28:30 EDT
I think the patch posted earlier is step in the right
direction, but full solution may need some more work.
This is under investigation.
Comment 17 Srikanth Sankaran CLA 2010-08-18 10:11:13 EDT
Created attachment 176892 [details]
Revised patch under test

This patch addresses three issues:

(1) With the earlier patch, the reconciler was aborting with
an NPE. The current patch addresses this issue.

(2) Added regression tests.

(3) With 1.5 projects with generics being added to the class
path of a 1.4 project, the reconciler starts producing several
unchecked warnings in 1.4 code. This ix fixed, so the behavior
is the same as the compiler (i.e no generics warnings in 1.4
code even though generic entities are references in their raw
(only possible) form from 1.4 code. 

Under test.
Comment 18 Srikanth Sankaran CLA 2010-08-18 11:30:51 EDT
Created attachment 176907 [details]
Proposed patch

Same patch as before, with a few typo's inside comments
taken care of. Passes all JDT/Core tests.
Comment 19 Srikanth Sankaran CLA 2010-08-18 11:31:29 EDT
Frederic, please review. TIA.
Comment 20 Frederic Fusier CLA 2010-08-19 03:59:58 EDT
Patch looks good to me
Comment 21 Srikanth Sankaran CLA 2010-08-19 04:54:18 EDT
Released in HEAD for 3.7 M2.
Comment 22 Olivier Thomann CLA 2010-09-14 10:33:57 EDT
Verified for 3.7M2 using I20100914-0100.
I could no longer get reconcile errors using this build.
Comment 23 Srikanth Sankaran CLA 2010-11-02 18:15:09 EDT
*** Bug 179195 has been marked as a duplicate of this bug. ***