Bug 179195 - Strange errors when mixing java 1.4 and 5.0 projects
Summary: Strange errors when mixing java 1.4 and 5.0 projects
Status: VERIFIED DUPLICATE of bug 305259
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-25 11:06 EDT by Max Gilead CLA
Modified: 2010-12-07 12:30 EST (History)
4 users (show)

See Also:


Attachments
test case (1.99 KB, application/octet-stream)
2007-03-25 11:07 EDT, Max Gilead CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Max Gilead CLA 2007-03-25 11:06:56 EDT
Eclipse reports strange errors when using Java 1.5+ project from Java 1.4 project. There are no errors in Problems tab but error is shown in editor. In the attached test case problem shows in Test14 project in file src/Test14.java in line:

test.add(new java.io.File("foo"));

'add' is marked as error: "The method add(File) is undefined for the type 'Test15'". I understand that Eclipse somehow compiles parts of Java 1.4 project which don't use Java 5.0 features and show only these parts but user isn't told about it.

QuickFix suggests following solutions:
- create method 'add(File)' in type 'Test15'
- add cast to 'test'
- rename in file

First suggestion is clearly wrong as this method already exists (albeit using Java 5.0 features). Second quick fix produces garbage code:

((Object)test).add(new java.io.File("foo"));

What's interesting is that resulting project runs perfectly fine both from command line and from within Eclipse.


I must admit I have no clear suggestion about how this problem should be resolved, but current behavior is misleading (invalid error message), incorrect (invalid quick fix suggestions) and incoherent (errors are shown, but project compiles and runs fine). It's obvious that user should either be told exactly what is wrong or, preferably, no errors should be reported at all (after all, resulting code runs fine!).
Comment 1 Max Gilead CLA 2007-03-25 11:07:52 EDT
Created attachment 61923 [details]
test case

Test case
Comment 2 Jerome Lanneluc CLA 2007-03-26 12:44:24 EDT
Eric, please check if this is the same problem as bug 100982. If it is, we'll make it a duplicate.
Comment 3 Eric Jodet CLA 2007-03-27 07:56:40 EDT
(In reply to comment #2)
Jérôme,
the problem here seems to be different than the one in bug 100982.

In this one, we have 2 projects:
a 5.0 compatible one
a 1.4 compatible one referencing the 5.0 compatible one.

This issue here is that the LookupEnvironment.globalOptions (compiler options) is determined by the
caller - here the 1.4 project. Hence, when checking the sourceLevel for the referenced method (supposed to be at 5.0 level),
we always are at 1.4 level.

For the current bug, the consequence of this issue is made visible in MethodScope.createMethod(AbstractMethodDeclaration),
at:
if (argLength > 0 && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {

In the bug scenario, the calling CU source level has a 1.4 source level,
whereas the referenced method in the second project has a 1.4 source level.

As a consequence, though we found it, we won't register any binding for the type parameter.
Hence, the add(T o) method is not found and the error is raised in the editor.
Comment 4 Jared Burns CLA 2007-04-24 20:14:32 EDT
I'm hitting this same problem. We've got a 1.4 compatible plugin which references a 5.0 plugin that just changed a method signature to use generics. Now my editors are full of fake errors, which makes editing them a scary experience...

Is there any way to workaround this issue?
Comment 5 Srikanth Sankaran CLA 2010-11-02 18:15:09 EDT
I am not able to reproduce this on 3.7 M1, but not on
3.7 M3. Closing as duplicate of bug 305259

*** This bug has been marked as a duplicate of bug 305259 ***
Comment 6 Srikanth Sankaran CLA 2010-11-02 18:17:44 EDT
(In reply to comment #5)
> I am not able to reproduce this on 3.7 M1, but not on


Grrr. It is 3.45 AM here and it shows - I meant to say I am able to
reproduce this on 3.7 M1, but not on 3.7 M3.
Comment 7 Ayushman Jain CLA 2010-12-07 04:44:19 EST
Verified for 3.7M4 using build I20101205-2000.
Comment 8 Olivier Thomann CLA 2010-12-07 12:30:56 EST
Verified using I20101207-0250 (4.1 I-build)