Community
Participate
Working Groups
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!).
Created attachment 61923 [details] test case Test case
Eric, please check if this is the same problem as bug 100982. If it is, we'll make it a duplicate.
(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.
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?
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 ***
(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.
Verified for 3.7M4 using build I20101205-2000.
Verified using I20101207-0250 (4.1 I-build)