View | Details | Raw Unified | Return to bug 305259 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-1 / +7 lines)
Lines 564-570 Link Here
564
	 * @param checkForErasedCandidateCollisions
564
	 * @param checkForErasedCandidateCollisions
565
	 */
565
	 */
566
	protected boolean connectTypeVariables(TypeParameter[] typeParameters, boolean checkForErasedCandidateCollisions) {
566
	protected boolean connectTypeVariables(TypeParameter[] typeParameters, boolean checkForErasedCandidateCollisions) {
567
		if (typeParameters == null || compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) return true;
567
		/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 - We used to not bother with connecting
568
		   type variables if source level is < 1.5. This creates problem in the reconciler if a 1.4
569
		   project references the generified API of a 1.5 project. The "current" project's source
570
		   level cannot be decide this question for some other project. Now if we see type parameters
571
		   at all, we assume that the concerned java element has some legitimate business with them.
572
		 */
573
		if (typeParameters == null || typeParameters.length == 0) return true;
568
		Map invocations = new HashMap(2);
574
		Map invocations = new HashMap(2);
569
		boolean noProblems = true;
575
		boolean noProblems = true;
570
		// preinitializing each type variable
576
		// preinitializing each type variable
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+6 lines)
Lines 6057-6062 Link Here
6057
		location.sourceEnd);
6057
		location.sourceEnd);
6058
}
6058
}
6059
public void rawTypeReference(ASTNode location, TypeBinding type) {
6059
public void rawTypeReference(ASTNode location, TypeBinding type) {
6060
	if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
6060
	type = type.leafComponentType();
6061
	type = type.leafComponentType();
6061
    this.handle(
6062
    this.handle(
6062
		IProblem.RawTypeReference,
6063
		IProblem.RawTypeReference,
Lines 6936-6941 Link Here
6936
		end);
6937
		end);
6937
}
6938
}
6938
public void unsafeCast(CastExpression castExpression, Scope scope) {
6939
public void unsafeCast(CastExpression castExpression, Scope scope) {
6940
	if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
6939
	int severity = computeSeverity(IProblem.UnsafeGenericCast);
6941
	int severity = computeSeverity(IProblem.UnsafeGenericCast);
6940
	if (severity == ProblemSeverities.Ignore) return;
6942
	if (severity == ProblemSeverities.Ignore) return;
6941
	TypeBinding castedExpressionType = castExpression.expression.resolvedType;
6943
	TypeBinding castedExpressionType = castExpression.expression.resolvedType;
Lines 6966-6971 Link Here
6966
		location.sourceEnd);
6968
		location.sourceEnd);
6967
}
6969
}
6968
public void unsafeRawFieldAssignment(FieldBinding field, TypeBinding expressionType, ASTNode location) {
6970
public void unsafeRawFieldAssignment(FieldBinding field, TypeBinding expressionType, ASTNode location) {
6971
	if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
6969
	int severity = computeSeverity(IProblem.UnsafeRawFieldAssignment);
6972
	int severity = computeSeverity(IProblem.UnsafeRawFieldAssignment);
6970
	if (severity == ProblemSeverities.Ignore) return;
6973
	if (severity == ProblemSeverities.Ignore) return;
6971
	this.handle(
6974
	this.handle(
Lines 6979-6984 Link Here
6979
		nodeSourceEnd(field, location));
6982
		nodeSourceEnd(field, location));
6980
}
6983
}
6981
public void unsafeRawGenericMethodInvocation(ASTNode location, MethodBinding rawMethod, TypeBinding[] argumentTypes) {
6984
public void unsafeRawGenericMethodInvocation(ASTNode location, MethodBinding rawMethod, TypeBinding[] argumentTypes) {
6985
	if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
6982
	boolean isConstructor = rawMethod.isConstructor();
6986
	boolean isConstructor = rawMethod.isConstructor();
6983
	int severity = computeSeverity(isConstructor ? IProblem.UnsafeRawGenericConstructorInvocation : IProblem.UnsafeRawGenericMethodInvocation);
6987
	int severity = computeSeverity(isConstructor ? IProblem.UnsafeRawGenericConstructorInvocation : IProblem.UnsafeRawGenericMethodInvocation);
6984
	if (severity == ProblemSeverities.Ignore) return;
6988
	if (severity == ProblemSeverities.Ignore) return;
Lines 7021-7026 Link Here
7021
    }
7025
    }
7022
}
7026
}
7023
public void unsafeRawInvocation(ASTNode location, MethodBinding rawMethod) {
7027
public void unsafeRawInvocation(ASTNode location, MethodBinding rawMethod) {
7028
	if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
7024
	boolean isConstructor = rawMethod.isConstructor();
7029
	boolean isConstructor = rawMethod.isConstructor();
7025
	int severity = computeSeverity(isConstructor ? IProblem.UnsafeRawConstructorInvocation : IProblem.UnsafeRawMethodInvocation);
7030
	int severity = computeSeverity(isConstructor ? IProblem.UnsafeRawConstructorInvocation : IProblem.UnsafeRawMethodInvocation);
7026
	if (severity == ProblemSeverities.Ignore) return;
7031
	if (severity == ProblemSeverities.Ignore) return;
Lines 7095-7100 Link Here
7095
			end);
7100
			end);
7096
}
7101
}
7097
public void unsafeTypeConversion(Expression expression, TypeBinding expressionType, TypeBinding expectedType) {
7102
public void unsafeTypeConversion(Expression expression, TypeBinding expressionType, TypeBinding expectedType) {
7103
	if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
7098
	int severity = computeSeverity(IProblem.UnsafeTypeConversion);
7104
	int severity = computeSeverity(IProblem.UnsafeTypeConversion);
7099
	if (severity == ProblemSeverities.Ignore) return;
7105
	if (severity == ProblemSeverities.Ignore) return;
7100
	this.handle(
7106
	this.handle(
(-)model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java (-13 / +26 lines)
Lines 96-115 Link Here
96
96
97
		CompilationResult result =
97
		CompilationResult result =
98
			new CompilationResult(sourceTypes[0].getFileName(), 1, 1, this.options.maxProblemsPerUnit);
98
			new CompilationResult(sourceTypes[0].getFileName(), 1, 1, this.options.maxProblemsPerUnit);
99
		
100
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259, build the compilation unit in its own sand box.
101
		final long savedComplianceLevel = this.options.complianceLevel;
102
		final long savedSourceLevel = this.options.sourceLevel;
103
		
104
		try {
105
			IJavaProject project = ((SourceTypeElementInfo) sourceTypes[0]).getHandle().getJavaProject();
106
			this.options.complianceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
107
			this.options.sourceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_SOURCE, true));
108
109
			// need to hold onto this
110
			CompilationUnitDeclaration unit =
111
				SourceTypeConverter.buildCompilationUnit(
112
						sourceTypes,//sourceTypes[0] is always toplevel here
113
						SourceTypeConverter.FIELD_AND_METHOD // need field and methods
114
						| SourceTypeConverter.MEMBER_TYPE // need member types
115
						| SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization
116
						this.lookupEnvironment.problemReporter,
117
						result);
99
118
100
		// need to hold onto this
119
			if (unit != null) {
101
		CompilationUnitDeclaration unit =
120
				this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
102
			SourceTypeConverter.buildCompilationUnit(
121
				this.lookupEnvironment.completeTypeBindings(unit);
103
				sourceTypes,//sourceTypes[0] is always toplevel here
122
			}
104
				SourceTypeConverter.FIELD_AND_METHOD // need field and methods
123
		} finally {
105
				| SourceTypeConverter.MEMBER_TYPE // need member types
124
			this.options.complianceLevel = savedComplianceLevel;
106
				| SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization
125
			this.options.sourceLevel = savedSourceLevel;
107
				this.lookupEnvironment.problemReporter,
108
				result);
109
110
		if (unit != null) {
111
			this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
112
			this.lookupEnvironment.completeTypeBindings(unit);
113
		}
126
		}
114
	}
127
	}
115
128
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (+134 lines)
Lines 4498-4501 Link Here
4498
			ast
4498
			ast
4499
		);
4499
		);
4500
}
4500
}
4501
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
4502
public void testGenericAPIUsageFromA14Project() throws CoreException {
4503
	IJavaProject project14 = null;
4504
	IJavaProject project15 = null;
4505
	try {
4506
		project15 = createJavaProject("Reconciler15API", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
4507
		createFolder("/Reconciler15API/src/p2");
4508
		createFile(
4509
			"/Reconciler15API/src/p2/BundleContext.java",
4510
			"package p2;\n" +
4511
			"public class BundleContext {\n" +
4512
			"  public <S> S getService(S s) {\n" +
4513
			"      return null;\n" +
4514
			"  }\n" +
4515
			"}"
4516
		);
4517
		project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
4518
		project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
4519
		project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
4520
		
4521
		project14 = createJavaProject("Reconciler1415", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
4522
		project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
4523
		project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
4524
		project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
4525
		
4526
		IClasspathEntry[] oldClasspath = project14.getRawClasspath();
4527
		int oldLength = oldClasspath.length;
4528
		IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1];
4529
		System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength);
4530
		newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Reconciler15API"));
4531
		project14.setRawClasspath(newClasspath, null);
4532
		
4533
		createFolder("/Reconciler1415/src/p1");
4534
		String source = 
4535
			"package p1;\n" +
4536
			"import p2.BundleContext;\n" +
4537
			"public class X {\n" +
4538
			"  public static void main(BundleContext context, String string) {\n" +
4539
			"  String s = (String) context.getService(string); \n" +
4540
			"  }\n" +
4541
			"}";
4542
4543
		createFile(
4544
			"/Reconciler1415/src/p1/X.java",
4545
			source
4546
		);
4547
		
4548
		this.workingCopies = new ICompilationUnit[1];
4549
		char[] sourceChars = source.toCharArray();
4550
		this.problemRequestor.initialize(sourceChars);
4551
		this.workingCopies[0] = getCompilationUnit("/Reconciler1415/src/p1/X.java").getWorkingCopy(this.wcOwner, null);
4552
		assertProblems(
4553
			"Unexpected problems",
4554
			"----------\n" + 
4555
			"1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + 
4556
			"	String s = (String) context.getService(string); \n" + 
4557
			"	       ^\n" + 
4558
			"The local variable s is never read\n" + 
4559
			"----------\n"
4560
		);
4561
	} finally {
4562
		if (project14 != null)
4563
			deleteProject(project14);
4564
		if (project15 != null)
4565
			deleteProject(project15);
4566
	}
4567
}
4568
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 (same as above, but with a JSR14 target)
4569
public void testGenericAPIUsageFromA14Project2() throws CoreException {
4570
	IJavaProject project14 = null;
4571
	IJavaProject project15 = null;
4572
	try {
4573
		project15 = createJavaProject("Reconciler15API", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
4574
		createFolder("/Reconciler15API/src/p2");
4575
		createFile(
4576
			"/Reconciler15API/src/p2/BundleContext.java",
4577
			"package p2;\n" +
4578
			"public class BundleContext {\n" +
4579
			"  public <S> S getService(S s) {\n" +
4580
			"      return null;\n" +
4581
			"  }\n" +
4582
			"}"
4583
		);
4584
		project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
4585
		project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
4586
		project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
4587
		
4588
		project14 = createJavaProject("Reconciler1415", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
4589
		project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
4590
		project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
4591
		project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
4592
		
4593
		IClasspathEntry[] oldClasspath = project14.getRawClasspath();
4594
		int oldLength = oldClasspath.length;
4595
		IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1];
4596
		System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength);
4597
		newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Reconciler15API"));
4598
		project14.setRawClasspath(newClasspath, null);
4599
		
4600
		createFolder("/Reconciler1415/src/p1");
4601
		String source = 
4602
			"package p1;\n" +
4603
			"import p2.BundleContext;\n" +
4604
			"public class X {\n" +
4605
			"  public static void main(BundleContext context, String string) {\n" +
4606
			"  String s = (String) context.getService(string); \n" +
4607
			"  }\n" +
4608
			"}";
4609
4610
		createFile(
4611
			"/Reconciler1415/src/p1/X.java",
4612
			source
4613
		);
4614
		
4615
		this.workingCopies = new ICompilationUnit[1];
4616
		char[] sourceChars = source.toCharArray();
4617
		this.problemRequestor.initialize(sourceChars);
4618
		this.workingCopies[0] = getCompilationUnit("/Reconciler1415/src/p1/X.java").getWorkingCopy(this.wcOwner, null);
4619
		assertProblems(
4620
			"Unexpected problems",
4621
			"----------\n" + 
4622
			"1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + 
4623
			"	String s = (String) context.getService(string); \n" + 
4624
			"	       ^\n" + 
4625
			"The local variable s is never read\n" + 
4626
			"----------\n"
4627
		);
4628
	} finally {
4629
		if (project14 != null)
4630
			deleteProject(project14);
4631
		if (project15 != null)
4632
			deleteProject(project15);
4633
	}
4634
}
4501
}
4635
}

Return to bug 305259