### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.372 diff -u -r1.372 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 22 Jul 2010 04:25:46 -0000 1.372 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 18 Aug 2010 13:57:14 -0000 @@ -564,7 +564,13 @@ * @param checkForErasedCandidateCollisions */ protected boolean connectTypeVariables(TypeParameter[] typeParameters, boolean checkForErasedCandidateCollisions) { - if (typeParameters == null || compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) return true; + /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 - We used to not bother with connecting + type variables if source level is < 1.5. This creates problem in the reconciler if a 1.4 + project references the generified API of a 1.5 project. The "current" project's source + level cannot be decide this question for some other project. Now if we see type parameters + at all, we assume that the concerned java element has some legitimate business with them. + */ + if (typeParameters == null || typeParameters.length == 0) return true; Map invocations = new HashMap(2); boolean noProblems = true; // preinitializing each type variable Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.416 diff -u -r1.416 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 27 Jul 2010 17:43:21 -0000 1.416 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 18 Aug 2010 13:57:17 -0000 @@ -6057,6 +6057,7 @@ location.sourceEnd); } public void rawTypeReference(ASTNode location, TypeBinding type) { + if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 type = type.leafComponentType(); this.handle( IProblem.RawTypeReference, @@ -6936,6 +6937,7 @@ end); } public void unsafeCast(CastExpression castExpression, Scope scope) { + if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 int severity = computeSeverity(IProblem.UnsafeGenericCast); if (severity == ProblemSeverities.Ignore) return; TypeBinding castedExpressionType = castExpression.expression.resolvedType; @@ -6966,6 +6968,7 @@ location.sourceEnd); } public void unsafeRawFieldAssignment(FieldBinding field, TypeBinding expressionType, ASTNode location) { + if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 int severity = computeSeverity(IProblem.UnsafeRawFieldAssignment); if (severity == ProblemSeverities.Ignore) return; this.handle( @@ -6979,6 +6982,7 @@ nodeSourceEnd(field, location)); } public void unsafeRawGenericMethodInvocation(ASTNode location, MethodBinding rawMethod, TypeBinding[] argumentTypes) { + if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 boolean isConstructor = rawMethod.isConstructor(); int severity = computeSeverity(isConstructor ? IProblem.UnsafeRawGenericConstructorInvocation : IProblem.UnsafeRawGenericMethodInvocation); if (severity == ProblemSeverities.Ignore) return; @@ -7021,6 +7025,7 @@ } } public void unsafeRawInvocation(ASTNode location, MethodBinding rawMethod) { + if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 boolean isConstructor = rawMethod.isConstructor(); int severity = computeSeverity(isConstructor ? IProblem.UnsafeRawConstructorInvocation : IProblem.UnsafeRawMethodInvocation); if (severity == ProblemSeverities.Ignore) return; @@ -7095,6 +7100,7 @@ end); } public void unsafeTypeConversion(Expression expression, TypeBinding expressionType, TypeBinding expectedType) { + if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 int severity = computeSeverity(IProblem.UnsafeTypeConversion); if (severity == ProblemSeverities.Ignore) return; this.handle( Index: model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java,v retrieving revision 1.67 diff -u -r1.67 CompilationUnitProblemFinder.java --- model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java 4 May 2010 14:04:56 -0000 1.67 +++ model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java 18 Aug 2010 13:57:17 -0000 @@ -96,20 +96,33 @@ CompilationResult result = new CompilationResult(sourceTypes[0].getFileName(), 1, 1, this.options.maxProblemsPerUnit); + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259, build the compilation unit in its own sand box. + final long savedComplianceLevel = this.options.complianceLevel; + final long savedSourceLevel = this.options.sourceLevel; + + try { + IJavaProject project = ((SourceTypeElementInfo) sourceTypes[0]).getHandle().getJavaProject(); + this.options.complianceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true)); + this.options.sourceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_SOURCE, true)); + + // need to hold onto this + CompilationUnitDeclaration unit = + SourceTypeConverter.buildCompilationUnit( + sourceTypes,//sourceTypes[0] is always toplevel here + SourceTypeConverter.FIELD_AND_METHOD // need field and methods + | SourceTypeConverter.MEMBER_TYPE // need member types + | SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization + this.lookupEnvironment.problemReporter, + result); - // need to hold onto this - CompilationUnitDeclaration unit = - SourceTypeConverter.buildCompilationUnit( - sourceTypes,//sourceTypes[0] is always toplevel here - SourceTypeConverter.FIELD_AND_METHOD // need field and methods - | SourceTypeConverter.MEMBER_TYPE // need member types - | SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization - this.lookupEnvironment.problemReporter, - result); - - if (unit != null) { - this.lookupEnvironment.buildTypeBindings(unit, accessRestriction); - this.lookupEnvironment.completeTypeBindings(unit); + if (unit != null) { + this.lookupEnvironment.buildTypeBindings(unit, accessRestriction); + this.lookupEnvironment.completeTypeBindings(unit); + } + } finally { + this.options.complianceLevel = savedComplianceLevel; + this.options.sourceLevel = savedSourceLevel; } } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java,v retrieving revision 1.153 diff -u -r1.153 ReconcilerTests.java --- src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 13 Jan 2010 16:35:59 -0000 1.153 +++ src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 18 Aug 2010 13:57:22 -0000 @@ -4498,4 +4498,138 @@ ast ); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 +public void testGenericAPIUsageFromA14Project() throws CoreException { + IJavaProject project14 = null; + IJavaProject project15 = null; + try { + project15 = createJavaProject("Reconciler15API", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin"); + createFolder("/Reconciler15API/src/p2"); + createFile( + "/Reconciler15API/src/p2/BundleContext.java", + "package p2;\n" + + "public class BundleContext {\n" + + " public S getService(S s) {\n" + + " return null;\n" + + " }\n" + + "}" + ); + project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + + project14 = createJavaProject("Reconciler1415", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin"); + project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4); + project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4); + + IClasspathEntry[] oldClasspath = project14.getRawClasspath(); + int oldLength = oldClasspath.length; + IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1]; + System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength); + newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Reconciler15API")); + project14.setRawClasspath(newClasspath, null); + + createFolder("/Reconciler1415/src/p1"); + String source = + "package p1;\n" + + "import p2.BundleContext;\n" + + "public class X {\n" + + " public static void main(BundleContext context, String string) {\n" + + " String s = (String) context.getService(string); \n" + + " }\n" + + "}"; + + createFile( + "/Reconciler1415/src/p1/X.java", + source + ); + + this.workingCopies = new ICompilationUnit[1]; + char[] sourceChars = source.toCharArray(); + this.problemRequestor.initialize(sourceChars); + this.workingCopies[0] = getCompilationUnit("/Reconciler1415/src/p1/X.java").getWorkingCopy(this.wcOwner, null); + assertProblems( + "Unexpected problems", + "----------\n" + + "1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + + " String s = (String) context.getService(string); \n" + + " ^\n" + + "The local variable s is never read\n" + + "----------\n" + ); + } finally { + if (project14 != null) + deleteProject(project14); + if (project15 != null) + deleteProject(project15); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 (same as above, but with a JSR14 target) +public void testGenericAPIUsageFromA14Project2() throws CoreException { + IJavaProject project14 = null; + IJavaProject project15 = null; + try { + project15 = createJavaProject("Reconciler15API", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin"); + createFolder("/Reconciler15API/src/p2"); + createFile( + "/Reconciler15API/src/p2/BundleContext.java", + "package p2;\n" + + "public class BundleContext {\n" + + " public S getService(S s) {\n" + + " return null;\n" + + " }\n" + + "}" + ); + project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4); + + project14 = createJavaProject("Reconciler1415", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin"); + project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4); + project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4); + + IClasspathEntry[] oldClasspath = project14.getRawClasspath(); + int oldLength = oldClasspath.length; + IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1]; + System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength); + newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Reconciler15API")); + project14.setRawClasspath(newClasspath, null); + + createFolder("/Reconciler1415/src/p1"); + String source = + "package p1;\n" + + "import p2.BundleContext;\n" + + "public class X {\n" + + " public static void main(BundleContext context, String string) {\n" + + " String s = (String) context.getService(string); \n" + + " }\n" + + "}"; + + createFile( + "/Reconciler1415/src/p1/X.java", + source + ); + + this.workingCopies = new ICompilationUnit[1]; + char[] sourceChars = source.toCharArray(); + this.problemRequestor.initialize(sourceChars); + this.workingCopies[0] = getCompilationUnit("/Reconciler1415/src/p1/X.java").getWorkingCopy(this.wcOwner, null); + assertProblems( + "Unexpected problems", + "----------\n" + + "1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + + " String s = (String) context.getService(string); \n" + + " ^\n" + + "The local variable s is never read\n" + + "----------\n" + ); + } finally { + if (project14 != null) + deleteProject(project14); + if (project15 != null) + deleteProject(project15); + } +} }