Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 185200 Details for
Bug 322817
Compiler option to ignore unavoidable type safety problems due to raw APIs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Revised patch
patch.txt (text/plain), 58.58 KB, created by
Srikanth Sankaran
on 2010-12-15 00:51:03 EST
(
hide
)
Description:
Revised patch
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2010-12-15 00:51:03 EST
Size:
58.58 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v >retrieving revision 1.356 >diff -u -r1.356 Main.java >--- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 26 Oct 2010 17:24:15 -0000 1.356 >+++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 15 Dec 2010 05:43:17 -0000 >@@ -3530,6 +3530,11 @@ > } else if (token.equals("unusedTypeArgs")) { //$NON-NLS-1$ > setSeverity(CompilerOptions.OPTION_ReportUnusedTypeArgumentsForMethodInvocation, severity, isEnabling); > return; >+ } else if (token.equals("unavoidableGenericProblems")) { //$NON-NLS-1$ >+ this.options.put( >+ CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, >+ isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); >+ return; > } > break; > case 'v' : >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v >retrieving revision 1.104 >diff -u -r1.104 ASTNode.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 22 Oct 2010 22:42:55 -0000 1.104 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 15 Dec 2010 05:43:18 -0000 >@@ -343,7 +343,9 @@ > if ((invocationStatus & INVOCATION_ARGUMENT_WILDCARD) != 0) { > scope.problemReporter().wildcardInvocation((ASTNode)invocationSite, receiverType, method, argumentTypes); > } else if (!method.isStatic() && !receiverType.isUnboundWildcard() && method.declaringClass.isRawType() && method.hasSubstitutedParameters()) { >- scope.problemReporter().unsafeRawInvocation((ASTNode)invocationSite, method); >+ if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || receiver == null || !receiver.forcedToBeRaw(scope.referenceContext())) { >+ scope.problemReporter().unsafeRawInvocation((ASTNode)invocationSite, method); >+ } > } else if (rawOriginalGenericMethod != null > || uncheckedBoundCheck > || ((invocationStatus & INVOCATION_ARGUMENT_UNCHECKED) != 0 >Index: compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java,v >retrieving revision 1.136 >diff -u -r1.136 CastExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 12 Aug 2010 16:58:28 -0000 1.136 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 15 Dec 2010 05:43:18 -0000 >@@ -494,7 +494,9 @@ > if (isLegal) { > this.expression.computeConversion(scope, castType, expressionType); > if ((this.bits & ASTNode.UnsafeCast) != 0) { // unsafe cast >- scope.problemReporter().unsafeCast(this, scope); >+ if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || !this.expression.forcedToBeRaw(scope.referenceContext())) { >+ scope.problemReporter().unsafeCast(this, scope); >+ } > } else { > if (castType.isRawType() && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore){ > scope.problemReporter().rawTypeReference(this.type, castType); >Index: compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java,v >retrieving revision 1.131 >diff -u -r1.131 Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 15 Sep 2010 16:10:50 -0000 1.131 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 15 Dec 2010 05:43:18 -0000 >@@ -21,6 +21,7 @@ > import org.eclipse.jdt.internal.compiler.flow.FlowContext; > import org.eclipse.jdt.internal.compiler.flow.FlowInfo; > import org.eclipse.jdt.internal.compiler.impl.Constant; >+import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; > import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; > import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; > import org.eclipse.jdt.internal.compiler.lookup.Binding; >@@ -958,6 +959,30 @@ > } > return expressionType; > } >+/** >+ * Returns true if the receiver is forced to be of raw type either to satisfy the contract imposed >+ * by a super type or because it *is* raw and the current type has no control over it (i.e the rawness >+ * originates from some other file. >+ */ >+public boolean forcedToBeRaw(ReferenceContext referenceContext) { >+ if (this instanceof NameReference) { >+ final Binding receiverBinding = ((NameReference) this).binding; >+ if (receiverBinding.isParameter() && (((LocalVariableBinding) receiverBinding).tagBits & TagBits.ForcedToBeRawType) != 0) { >+ return true; // parameter is forced to be raw since super method uses raw types. >+ } >+ } else if (this instanceof MessageSend) { >+ if (!CharOperation.equals(((MessageSend) this).binding.declaringClass.getFileName(), >+ referenceContext.compilationResult().getFileName())) { // problem is rooted elsewhere >+ return true; >+ } >+ } else if (this instanceof FieldReference) { >+ if (!CharOperation.equals(((FieldReference) this).binding.declaringClass.getFileName(), >+ referenceContext.compilationResult().getFileName())) { // problem is rooted elsewhere >+ return true; >+ } >+ } >+ return false; >+} > > /** > * Returns an object which can be used to identify identical JSR sequence targets >Index: compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java,v >retrieving revision 1.235 >diff -u -r1.235 CompilerOptions.java >--- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 21 Oct 2010 19:59:58 -0000 1.235 >+++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 15 Dec 2010 05:43:18 -0000 >@@ -87,6 +87,7 @@ > public static final String OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference = "org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference"; //$NON-NLS-1$ > public static final String OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = "org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable"; //$NON-NLS-1$ > public static final String OPTION_ReportUnqualifiedFieldAccess = "org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess"; //$NON-NLS-1$ >+ public static final String OPTION_ReportUnavoidableGenericTypeProblems = "org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems"; //$NON-NLS-1$ > public static final String OPTION_ReportUncheckedTypeOperation = "org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation"; //$NON-NLS-1$ > public static final String OPTION_ReportRawTypeReference = "org.eclipse.jdt.core.compiler.problem.rawTypeReference"; //$NON-NLS-1$ > public static final String OPTION_ReportFinalParameterBound = "org.eclipse.jdt.core.compiler.problem.finalParameterBound"; //$NON-NLS-1$ >@@ -357,6 +358,8 @@ > public boolean ignoreMethodBodies; > /** Raise null related warnings for variables tainted inside an assert statement (java 1.4 and above)*/ > public boolean includeNullInfoFromAsserts; >+ /** Controls whether forced generic type problems get reported */ >+ public boolean reportUnavoidableGenericTypeProblems; > > // keep in sync with warningTokenToIrritant and warningTokenFromIrritant > public final static String[] warningTokens = { >@@ -871,6 +874,7 @@ > optionsMap.put(OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference, this.reportUnusedDeclaredThrownExceptionIncludeDocCommentReference ? ENABLED : DISABLED); > optionsMap.put(OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, this.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable ? ENABLED : DISABLED); > optionsMap.put(OPTION_ReportUnqualifiedFieldAccess, getSeverityString(UnqualifiedFieldAccess)); >+ optionsMap.put(OPTION_ReportUnavoidableGenericTypeProblems, this.reportUnavoidableGenericTypeProblems ? ENABLED : DISABLED); > optionsMap.put(OPTION_ReportUncheckedTypeOperation, getSeverityString(UncheckedTypeOperation)); > optionsMap.put(OPTION_ReportRawTypeReference, getSeverityString(RawTypeReference)); > optionsMap.put(OPTION_ReportFinalParameterBound, getSeverityString(FinalParameterBound)); >@@ -1012,6 +1016,8 @@ > // constructor/setter parameter hiding > this.reportSpecialParameterHidingField = false; > >+ this.reportUnavoidableGenericTypeProblems = true; >+ > // check javadoc comments tags > this.reportInvalidJavadocTagsVisibility = ClassFileConstants.AccPublic; > this.reportInvalidJavadocTags = false; >@@ -1193,6 +1199,13 @@ > this.reportSpecialParameterHidingField = false; > } > } >+ if ((optionValue = optionsMap.get(OPTION_ReportUnavoidableGenericTypeProblems)) != null) { >+ if (ENABLED.equals(optionValue)) { >+ this.reportUnavoidableGenericTypeProblems = true; >+ } else if (DISABLED.equals(optionValue)) { >+ this.reportUnavoidableGenericTypeProblems = false; >+ } >+ } > if ((optionValue = optionsMap.get(OPTION_ReportDeadCodeInTrivialIfStatement )) != null) { > if (ENABLED.equals(optionValue)) { > this.reportDeadCodeInTrivialIfStatement = true; >@@ -1516,6 +1529,7 @@ > buf.append("\n\t- report unused parameter include doc comment reference : ").append(this.reportUnusedParameterIncludeDocCommentReference ? ENABLED : DISABLED); //$NON-NLS-1$ > buf.append("\n\t- report constructor/setter parameter hiding existing field : ").append(this.reportSpecialParameterHidingField ? ENABLED : DISABLED); //$NON-NLS-1$ > buf.append("\n\t- inline JSR bytecode : ").append(this.inlineJsrBytecode ? ENABLED : DISABLED); //$NON-NLS-1$ >+ buf.append("\n\t- report unavoidable generic type problems : ").append(this.reportUnavoidableGenericTypeProblems ? ENABLED : DISABLED); //$NON-NLS-1$ > buf.append("\n\t- unsafe type operation: ").append(getSeverityString(UncheckedTypeOperation)); //$NON-NLS-1$ > buf.append("\n\t- unsafe raw type: ").append(getSeverityString(RawTypeReference)); //$NON-NLS-1$ > buf.append("\n\t- final bound for type parameter: ").append(getSeverityString(FinalParameterBound)); //$NON-NLS-1$ >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java,v >retrieving revision 1.36 >diff -u -r1.36 Binding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java 14 Jul 2010 10:37:16 -0000 1.36 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java 15 Dec 2010 05:43:18 -0000 >@@ -94,6 +94,9 @@ > public boolean isVolatile() { > return false; > } >+ public boolean isParameter() { >+ return false; >+ } > /* API > * Answer the problem id associated with the receiver. > * NoError if the receiver is a valid binding. >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java,v >retrieving revision 1.48 >diff -u -r1.48 LocalVariableBinding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java 22 Oct 2010 22:42:56 -0000 1.48 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java 15 Dec 2010 05:43:18 -0000 >@@ -41,6 +41,7 @@ > public LocalVariableBinding(char[] name, TypeBinding type, int modifiers, boolean isArgument) { > super(name, type, modifiers, isArgument ? Constant.NotAConstant : null); > if (isArgument) this.tagBits |= TagBits.IsArgument; >+ this.tagBits &= ~TagBits.ForcedToBeRawType; > } > > // regular local variable or argument >@@ -244,4 +245,8 @@ > } > return s; > } >+ >+ public boolean isParameter() { >+ return ((this.tagBits & TagBits.IsArgument) != 0); >+ } > } >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java,v >retrieving revision 1.113 >diff -u -r1.113 MethodVerifier.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 17 Aug 2010 14:50:42 -0000 1.113 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 15 Dec 2010 05:43:18 -0000 >@@ -158,7 +158,7 @@ > if (reportIncompatibleReturnTypeError(currentMethod, inheritedMethod)) > continue nextMethod; > } >- >+ reportRawReferences(currentMethod, inheritedMethod); // if they were deferred, emit them now. > if (currentMethod.thrownExceptions != Binding.NO_EXCEPTIONS) > checkExceptions(currentMethod, inheritedMethod); > if (inheritedMethod.isFinal()) >@@ -185,6 +185,9 @@ > } > } > >+public void reportRawReferences(MethodBinding currentMethod, MethodBinding inheritedMethod) { >+ // nothing to do here. Real action happens at 1.5+ >+} > void checkConcreteInheritedMethod(MethodBinding concreteMethod, MethodBinding[] abstractMethods) { > // Remember that interfaces can only define public instance methods > if (concreteMethod.isStatic()) >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java,v >retrieving revision 1.120 >diff -u -r1.120 MethodVerifier15.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java 6 Nov 2010 12:24:51 -0000 1.120 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java 15 Dec 2010 05:43:18 -0000 >@@ -10,8 +10,16 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.lookup; > >+ >+import org.eclipse.jdt.internal.compiler.ast.ASTNode; >+import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; >+import org.eclipse.jdt.internal.compiler.ast.Argument; >+import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; > import org.eclipse.jdt.internal.compiler.ast.TypeParameter; >+import org.eclipse.jdt.internal.compiler.ast.TypeReference; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; >+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; >+import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; > import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; > import org.eclipse.jdt.internal.compiler.util.SimpleSet; > >@@ -398,6 +406,94 @@ > > return false; > } >+ >+void reportRawReferences() { >+ CompilerOptions compilerOptions = this.type.scope.compilerOptions(); >+ if (compilerOptions.sourceLevel < ClassFileConstants.JDK1_5 // shouldn't whine at all >+ || compilerOptions.reportUnavoidableGenericTypeProblems) { // must have already whined >+ return; >+ } >+ /* Code below is only for a method that does not override/implement a super type method. If it were to, >+ it would have been handled in checkAgainstInheritedMethods. >+ */ >+ Object [] methodArray = this.currentMethods.valueTable; >+ for (int s = methodArray.length; --s >= 0;) { >+ if (methodArray[s] == null) continue; >+ MethodBinding[] current = (MethodBinding[]) methodArray[s]; >+ for (int i = 0, length = current.length; i < length; i++) { >+ MethodBinding currentMethod = current[i]; >+ if ((currentMethod.modifiers & (ExtraCompilerModifiers.AccImplementing | ExtraCompilerModifiers.AccOverriding)) == 0) { >+ AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod(); >+ if (methodDecl == null) return; >+ TypeBinding [] parameterTypes = currentMethod.parameters; >+ Argument[] arguments = methodDecl.arguments; >+ for (int j = 0, size = currentMethod.parameters.length; j < size; j++) { >+ TypeBinding parameterType = parameterTypes[j]; >+ Argument arg = arguments[j]; >+ if (parameterType.leafComponentType().isRawType() >+ && compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore >+ && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0) { >+ methodDecl.scope.problemReporter().rawTypeReference(arg.type, parameterType); >+ } >+ } >+ if (!methodDecl.isConstructor() && methodDecl instanceof MethodDeclaration) { >+ TypeReference returnType = ((MethodDeclaration) methodDecl).returnType; >+ TypeBinding methodType = currentMethod.returnType; >+ if (returnType != null) { >+ if (methodType.leafComponentType().isRawType() >+ && compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore >+ && (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0) { >+ methodDecl.scope.problemReporter().rawTypeReference(returnType, methodType); >+ } >+ } >+ } >+ } >+ } >+ } >+} >+public void reportRawReferences(MethodBinding currentMethod, MethodBinding inheritedMethod) { >+ CompilerOptions compilerOptions = this.type.scope.compilerOptions(); >+ if (compilerOptions.sourceLevel < ClassFileConstants.JDK1_5 // shouldn't whine at all >+ || compilerOptions.reportUnavoidableGenericTypeProblems) { // must have already whined >+ return; >+ } >+ AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod(); >+ if (methodDecl == null) return; >+ TypeBinding [] parameterTypes = currentMethod.parameters; >+ TypeBinding [] inheritedParameterTypes = inheritedMethod.parameters; >+ Argument[] arguments = methodDecl.arguments; >+ for (int j = 0, size = currentMethod.parameters.length; j < size; j++) { >+ TypeBinding parameterType = parameterTypes[j]; >+ TypeBinding inheritedParameterType = inheritedParameterTypes[j]; >+ Argument arg = arguments[j]; >+ if (parameterType.leafComponentType().isRawType()) { >+ if (inheritedParameterType.leafComponentType().isRawType()) { >+ arg.binding.tagBits |= TagBits.ForcedToBeRawType; >+ } else { >+ if (compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore >+ && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0) { >+ methodDecl.scope.problemReporter().rawTypeReference(arg.type, parameterType); >+ } >+ } >+ } >+ } >+ TypeReference returnType = null; >+ if (!methodDecl.isConstructor() && methodDecl instanceof MethodDeclaration && (returnType = ((MethodDeclaration) methodDecl).returnType) != null) { >+ final TypeBinding inheritedMethodType = inheritedMethod.returnType; >+ final TypeBinding methodType = currentMethod.returnType; >+ if (methodType.leafComponentType().isRawType()) { >+ if (inheritedMethodType.leafComponentType().isRawType()) { >+ // >+ } else { >+ if ((returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0 >+ && compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) { >+ methodDecl.scope.problemReporter().rawTypeReference(returnType, methodType); >+ } >+ } >+ } >+ } >+ } >+ > void checkMethods() { > boolean mustImplementAbstractMethods = mustImplementAbstractMethods(); > boolean skipInheritedMethods = mustImplementAbstractMethods && canSkipInheritedMethods(); // have a single concrete superclass so only check overridden methods >@@ -903,6 +999,8 @@ > this.type.detectAnnotationCycle(); > > super.verify(); >+ >+ reportRawReferences(); > > for (int i = this.type.typeVariables.length; --i >= 0;) { > TypeVariableBinding var = this.type.typeVariables[i]; >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java,v >retrieving revision 1.182 >diff -u -r1.182 SourceTypeBinding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 27 Oct 2010 02:55:30 -0000 1.182 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 15 Dec 2010 05:43:19 -0000 >@@ -1365,7 +1365,7 @@ > if (count < size) > System.arraycopy(method.thrownExceptions, 0, method.thrownExceptions = new ReferenceBinding[count], 0, count); > } >- >+ final boolean reportUnavoidableGenericTypeProblems = this.scope.compilerOptions().reportUnavoidableGenericTypeProblems; > boolean foundArgProblem = false; > Argument[] arguments = methodDecl.arguments; > if (arguments != null) { >@@ -1377,7 +1377,20 @@ > if (arg.annotations != null) { > method.tagBits |= TagBits.HasParameterAnnotations; > } >- TypeBinding parameterType = arg.type.resolveType(methodDecl.scope, true /* check bounds*/); >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+ boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0; >+ TypeBinding parameterType; >+ if (deferRawTypeCheck) { >+ arg.type.bits |= ASTNode.IgnoreRawTypeCheck; >+ } >+ try { >+ parameterType = arg.type.resolveType(methodDecl.scope, true /* check bounds*/); >+ } finally { >+ if (deferRawTypeCheck) { >+ arg.type.bits &= ~ASTNode.IgnoreRawTypeCheck; >+ } >+ } >+ > if (parameterType == null) { > foundArgProblem = true; > } else if (parameterType == TypeBinding.VOID) { >@@ -1410,7 +1423,19 @@ > method.returnType = null; > foundReturnTypeProblem = true; > } else { >- TypeBinding methodType = returnType.resolveType(methodDecl.scope, true /* check bounds*/); >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+ boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems && (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0; >+ TypeBinding methodType; >+ if (deferRawTypeCheck) { >+ returnType.bits |= ASTNode.IgnoreRawTypeCheck; >+ } >+ try { >+ methodType = returnType.resolveType(methodDecl.scope, true /* check bounds*/); >+ } finally { >+ if (deferRawTypeCheck) { >+ returnType.bits &= ~ASTNode.IgnoreRawTypeCheck; >+ } >+ } > if (methodType == null) { > foundReturnTypeProblem = true; > } else if (methodType.isArrayType() && ((ArrayBinding) methodType).leafComponentType == TypeBinding.VOID) { >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java,v >retrieving revision 1.44 >diff -u -r1.44 TagBits.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 21 Sep 2010 14:02:58 -0000 1.44 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 15 Dec 2010 05:43:19 -0000 >@@ -35,6 +35,9 @@ > > // local variable > long NotInitialized = ASTNode.Bit9; >+ >+ // local variable >+ long ForcedToBeRawType = ASTNode.Bit10; > > // set when method has argument(s) that couldn't be resolved > long HasUnresolvedArguments = ASTNode.Bit10; >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.426 >diff -u -r1.426 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 19 Nov 2010 14:22:00 -0000 1.426 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 15 Dec 2010 05:43:19 -0000 >@@ -7130,6 +7130,9 @@ > 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; >+ if (!this.options.reportUnavoidableGenericTypeProblems && expression.forcedToBeRaw(this.referenceContext)) { >+ return; >+ } > this.handle( > IProblem.UnsafeTypeConversion, > new String[] { new String(expressionType.readableName()), new String(expectedType.readableName()), new String(expectedType.erasure().readableName()) }, >Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java,v >retrieving revision 1.80 >diff -u -r1.80 DefaultCodeFormatter.java >--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java 22 Feb 2010 11:01:46 -0000 1.80 >+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java 15 Dec 2010 05:43:19 -0000 >@@ -336,6 +336,7 @@ > optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED); > optionsMap.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED); > optionsMap.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, CompilerOptions.DISABLED); >+ optionsMap.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); > optionsMap.put(CompilerOptions.OPTION_MaxProblemPerUnit, String.valueOf(100)); > optionsMap.put(CompilerOptions.OPTION_InlineJsr, CompilerOptions.DISABLED); > this.defaultCompilerOptions = optionsMap; >Index: model/org/eclipse/jdt/core/JavaCore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v >retrieving revision 1.655 >diff -u -r1.655 JavaCore.java >--- model/org/eclipse/jdt/core/JavaCore.java 6 Oct 2010 13:57:36 -0000 1.655 >+++ model/org/eclipse/jdt/core/JavaCore.java 15 Dec 2010 05:43:20 -0000 >@@ -900,6 +900,22 @@ > */ > public static final String COMPILER_PB_RAW_TYPE_REFERENCE = PLUGIN_ID + ".compiler.problem.rawTypeReference"; //$NON-NLS-1$ > /** >+ * Compiler option ID: Reporting of Unavoidable Generic Type Problems. >+ * <p> When enabled, the compiler will issue an error or warning even when it detects a generic type problem >+ * that could not have been avoided by the programmer. As an example, a type may be forced to use raw types >+ * in its method signatures and return types because the methods it overrides from a super type are declared to >+ * use raw types in the first place. >+ * <dl> >+ * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems"</code></dd> >+ * <dt>Possible values:</dt><dd><code>{ "enabled", "disabled" }</code></dd> >+ * <dt>Default:</dt><dd><code>"enabled"</code></dd> >+ * </dl> >+ * @since 3.7 >+ * @category CompilerOptionID >+ */ >+ public static final String COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS = PLUGIN_ID + ".compiler.problem.unavoidableGenericTypeProblems"; //$NON-NLS-1$ >+ >+ /** > * Compiler option ID: Reporting final Bound for Type Parameter. > * <p>When enabled, the compiler will issue an error or a warning whenever a generic type parameter is associated with a > * bound corresponding to a final type; since final types cannot be further extended, the parameter is pretty useless. >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v >retrieving revision 1.220 >diff -u -r1.220 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 19 Nov 2010 14:21:58 -0000 1.220 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 15 Dec 2010 05:43:24 -0000 >@@ -1800,7 +1800,7 @@ > " <option key=\"org.eclipse.jdt.core.compiler.debug.sourceFile\" value=\"generate\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.doc.comment.support\" value=\"disabled\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.generateClassFiles\" value=\"enabled\"/>\n" + >- " <option key=\"org.eclipse.jdt.core.compiler.maxProblemPerUnit\" value=\"100\"/>\n" + >+ " <option key=\"org.eclipse.jdt.core.compiler.maxProblemPerUnit\" value=\"100\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.annotationSuperInterface\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.assertIdentifier\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.autoboxing\" value=\"ignore\"/>\n" + >@@ -1864,6 +1864,7 @@ > " <option key=\"org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.tasks\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.typeParameterHiding\" value=\"warning\"/>\n" + >+ " <option key=\"org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems\" value=\"enabled\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unhandledWarningToken\" value=\"warning\"/>\n" + >@@ -12070,4 +12071,73 @@ > new File(lib1Path).delete(); > } > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 -- with new option kicking in >+public void testReportingUnavoidableGenericProblems() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface Adaptable {\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ "}\n" + >+ "public class X implements Adaptable {\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " return null;\n" + >+ " }\n" + >+ " Zork z;\n" + >+ "}\n" >+ }, >+ "\"" + OUTPUT_DIR + File.separator + "X.java\"" >+ + " -1.5 -warn:-unavoidableGenericProblems -proc:none -d \"" + OUTPUT_DIR + "\"", >+ "", >+ "----------\n" + >+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n" + >+ "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 8)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" + >+ "2 problems (1 error, 1 warning)", >+ true); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 -- without new option kicking in >+public void testReportingUnavoidableGenericProblems2() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface Adaptable {\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ "}\n" + >+ "public class X implements Adaptable {\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " return null;\n" + >+ " }\n" + >+ " Zork z;\n" + >+ "}\n" >+ }, >+ "\"" + OUTPUT_DIR + File.separator + "X.java\"" >+ + " -1.5 -warn:+unavoidableGenericProblems -proc:none -d \"" + OUTPUT_DIR + "\"", >+ "", >+ "----------\n" + >+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n" + >+ "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 8)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" + >+ "3 problems (1 error, 2 warnings)", >+ true); >+} > } >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java,v >retrieving revision 1.4 >diff -u -r1.4 GenericsRegressionTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java 24 Nov 2010 04:51:13 -0000 1.4 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java 15 Dec 2010 05:43:24 -0000 >@@ -536,4 +536,625 @@ > }, > ""); // no specific success output string > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+public void test322817() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface Adaptable {\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ "}\n" + >+ "public class X implements Adaptable {\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+public void test322817b() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface Adaptable {\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ "}\n" + >+ "public class X implements Adaptable {\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " public Object getAdapter(Class clazz); \n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 5)\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+public void test322817c() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface Adaptable {\n" + >+ " public Object getAdapter(Class<String> clazz); \n" + >+ "}\n" + >+ "public class X implements Adaptable {\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 5)\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+public void test322817d() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface Adaptable {\n" + >+ " public Object getAdapter(Class<String> clazz); \n" + >+ "}\n" + >+ "public class X implements Adaptable {\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" + >+ "class Y extends X {\n" + >+ " @Override\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 5)\n" + >+ " public Object getAdapter(Class clazz) {\n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+public void test322817e() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "class Top {\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " public List get() { return null; } // OK to warn in 1.5 code\n" + >+ "}\n" + >+ "class Sub extends Top {\n" + >+ " @Override\n" + >+ " public void set(List arg) { // should not warn (overrides)\n" + >+ " }\n" + >+ " @Override\n" + >+ " public List get() { // should not warn (overrides)\n" + >+ " return super.get();\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 3)\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 4)\n" + >+ " public List get() { return null; } // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 >+public void test322817f() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "class Top {\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " public List<String> get() { return null; }\n" + >+ "}\n" + >+ "class Sub extends Top {\n" + >+ " @Override\n" + >+ " public void set(List arg) { // should not warn (overrides)\n" + >+ " }\n" + >+ " @Override\n" + >+ " public List get() { // should warn (super's return type is not raw)\n" + >+ " return super.get();\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 3)\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 11)\n" + >+ " public List get() { // should warn (super\'s return type is not raw)\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 11)\n" + >+ " public List get() { // should warn (super\'s return type is not raw)\n" + >+ " ^^^^\n" + >+ "Type safety: The return type List for get() from the type Sub needs unchecked conversion to conform to List<String> from the type Top\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Disable reporting of unavoidable problems) >+public void test322817g() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "Top.java", >+ "import java.util.List;\n" + >+ "public class Top {\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " public List get() { return null; } // OK to warn in 1.5 code\n" + >+ " List list; // OK to warn in 1.5 code\n" + >+ "}\n", >+ "Sub.java", >+ "import java.util.List;\n" + >+ "public class Sub extends Top {\n" + >+ " @Override\n" + >+ " public void set(List arg) { // should not warn (overrides)\n" + >+ " super.set(arg);\n" + >+ " arg.set(0, \"A\"); // should not warn ('arg' is forced raw)\n" + >+ " }\n" + >+ " @Override\n" + >+ " public List get() { // should not warn (overrides)\n" + >+ " return super.get();\n" + >+ " }\n" + >+ "}\n", >+ "X.java", >+ "import java.util.List;\n" + >+ "public class X {\n" + >+ " void run() {\n" + >+ " new Top().list.add(\"arg\"); // should not warn (uses raw field declared elsewhere)\n" + >+ " new Top().get().add(\"arg\"); // should not warn (uses raw API)\n" + >+ " List raw= new Top().get(); // OK to warn ('raw' declared here)\n" + >+ " raw.add(\"arg\"); // OK to warn ('raw' declared here)\n" + >+ " // When Top#get() is generified, both of the following will fail\n" + >+ " // with a compile error if type arguments don't match:\n" + >+ " List<String> unchecked= new Top().get(); // should not warn (forced)\n" + >+ " unchecked.add(\"x\");\n" + >+ " // Should not warn about unchecked cast, but should warn about\n" + >+ " // unnecessary cast:\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " cast.add(\"x\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in Top.java (at line 3)\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in Top.java (at line 4)\n" + >+ " public List get() { return null; } // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in Top.java (at line 5)\n" + >+ " List list; // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in X.java (at line 6)\n" + >+ " List raw= new Top().get(); // OK to warn (\'raw\' declared here)\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " raw.add(\"arg\"); // OK to warn (\'raw\' declared here)\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 14)\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from List to List<String>\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Enable reporting of unavoidable problems) >+public void test322817h() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); >+ this.runNegativeTest( >+ new String[] { >+ "Top.java", >+ "import java.util.List;\n" + >+ "public class Top {\n" + >+ " public void set(List arg) { }\n" + >+ " public List get() { return null; }\n" + >+ " List list;\n" + >+ "}\n", >+ "Sub.java", >+ "import java.util.List;\n" + >+ "public class Sub extends Top {\n" + >+ " @Override\n" + >+ " public void set(List arg) {\n" + >+ " super.set(arg);\n" + >+ " arg.set(0, \"A\");\n" + >+ " }\n" + >+ " @Override\n" + >+ " public List get() {\n" + >+ " return super.get();\n" + >+ " }\n" + >+ "}\n", >+ "X.java", >+ "import java.util.List;\n" + >+ "public class X {\n" + >+ " void run() {\n" + >+ " new Top().list.add(\"arg\");\n" + >+ " new Top().get().add(\"arg\");\n" + >+ " List raw= new Top().get();\n" + >+ " raw.add(\"arg\");\n" + >+ " List<String> unchecked= new Top().get();\n" + >+ " unchecked.add(\"x\");\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " cast.add(\"x\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in Top.java (at line 3)\n" + >+ " public void set(List arg) { }\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in Top.java (at line 4)\n" + >+ " public List get() { return null; }\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in Top.java (at line 5)\n" + >+ " List list;\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in Sub.java (at line 4)\n" + >+ " public void set(List arg) {\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in Sub.java (at line 6)\n" + >+ " arg.set(0, \"A\");\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method set(int, Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in Sub.java (at line 9)\n" + >+ " public List get() {\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in X.java (at line 4)\n" + >+ " new Top().list.add(\"arg\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 5)\n" + >+ " new Top().get().add(\"arg\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 6)\n" + >+ " List raw= new Top().get();\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 7)\n" + >+ " raw.add(\"arg\");\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 8)\n" + >+ " List<String> unchecked= new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The expression of type List needs unchecked conversion to conform to List<String>\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 10)\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from List to List<String>\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 10)\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from List to List<String>\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Default options) >+public void test322817i() { >+ Map customOptions = getCompilerOptions(); >+ this.runNegativeTest( >+ new String[] { >+ "Top.java", >+ "import java.util.List;\n" + >+ "public class Top {\n" + >+ " public void set(List arg) { }\n" + >+ " public List get() { return null; }\n" + >+ " List list;\n" + >+ "}\n", >+ "Sub.java", >+ "import java.util.List;\n" + >+ "public class Sub extends Top {\n" + >+ " @Override\n" + >+ " public void set(List arg) {\n" + >+ " super.set(arg);\n" + >+ " arg.set(0, \"A\");\n" + >+ " }\n" + >+ " @Override\n" + >+ " public List get() {\n" + >+ " return super.get();\n" + >+ " }\n" + >+ "}\n", >+ "X.java", >+ "import java.util.List;\n" + >+ "public class X {\n" + >+ " void run() {\n" + >+ " new Top().list.add(\"arg\");\n" + >+ " new Top().get().add(\"arg\");\n" + >+ " List raw= new Top().get();\n" + >+ " raw.add(\"arg\");\n" + >+ " List<String> unchecked= new Top().get();\n" + >+ " unchecked.add(\"x\");\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " cast.add(\"x\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in Top.java (at line 3)\n" + >+ " public void set(List arg) { }\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in Top.java (at line 4)\n" + >+ " public List get() { return null; }\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in Top.java (at line 5)\n" + >+ " List list;\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in Sub.java (at line 4)\n" + >+ " public void set(List arg) {\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in Sub.java (at line 6)\n" + >+ " arg.set(0, \"A\");\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method set(int, Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in Sub.java (at line 9)\n" + >+ " public List get() {\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in X.java (at line 4)\n" + >+ " new Top().list.add(\"arg\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 5)\n" + >+ " new Top().get().add(\"arg\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 6)\n" + >+ " List raw= new Top().get();\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 7)\n" + >+ " raw.add(\"arg\");\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 8)\n" + >+ " List<String> unchecked= new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The expression of type List needs unchecked conversion to conform to List<String>\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 10)\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from List to List<String>\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 10)\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from List to List<String>\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (all in same file) >+public void test322817j() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "class Top {\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " public List get() { return null; } // OK to warn in 1.5 code\n" + >+ "}\n" + >+ "class Sub extends Top {\n" + >+ " @Override\n" + >+ " public void set(List arg) { // should not warn (overrides)\n" + >+ " super.set(arg);\n" + >+ " arg.set(0, \"A\"); // should not warn ('arg' is forced raw)\n" + >+ " }\n" + >+ " @Override\n" + >+ " public List get() { // should not warn (overrides)\n" + >+ " return super.get();\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {\n" + >+ " void run() {\n" + >+ " new Top().get().add(\"arg\");\n" + >+ " List raw= new Top().get(); // OK to warn ('raw' declared here)\n" + >+ " raw.add(\"arg\"); // OK to warn ('raw' declared here)\n" + >+ " List<String> unchecked= new Top().get();\n" + >+ " unchecked.add(\"x\");\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " cast.add(\"x\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 3)\n" + >+ " public void set(List arg) { } // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 4)\n" + >+ " public List get() { return null; } // OK to warn in 1.5 code\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 19)\n" + >+ " new Top().get().add(\"arg\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 20)\n" + >+ " List raw= new Top().get(); // OK to warn (\'raw\' declared here)\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 21)\n" + >+ " raw.add(\"arg\"); // OK to warn (\'raw\' declared here)\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 22)\n" + >+ " List<String> unchecked= new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The expression of type List needs unchecked conversion to conform to List<String>\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 24)\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from List to List<String>\n" + >+ "----------\n" + >+ "8. WARNING in X.java (at line 24)\n" + >+ " List<String> cast= (List<String>) new Top().get();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from List to List<String>\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (make sure there is no NPE when receiver is null) >+public void test322817k() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.Arrays;\n" + >+ "import java.util.Set;\n" + >+ "import java.util.HashSet;\n" + >+ "public class X {\n" + >+ " public void foo(String[] elements) {\n" + >+ " Set set= new HashSet(Arrays.asList(elements));\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 6)\n" + >+ " Set set= new HashSet(Arrays.asList(elements));\n" + >+ " ^^^\n" + >+ "Set is a raw type. References to generic type Set<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 6)\n" + >+ " Set set= new HashSet(Arrays.asList(elements));\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The constructor HashSet(Collection) belongs to the raw type HashSet. References to generic type HashSet<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 6)\n" + >+ " Set set= new HashSet(Arrays.asList(elements));\n" + >+ " ^^^^^^^\n" + >+ "HashSet is a raw type. References to generic type HashSet<E> should be parameterized\n" + >+ "----------\n", >+ null, >+ true, >+ customOptions); >+} > } >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 322817
:
184023
|
184108
|
184788
|
184931
| 185200