### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java,v retrieving revision 1.74 diff -u -r1.74 AllocationExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 27 Jun 2008 16:03:55 -0000 1.74 +++ compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 23 Aug 2008 09:40:38 -0000 @@ -79,6 +79,9 @@ } public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { + if (!valueRequired && this.resolvedType.isCompatibleWith(currentScope.getJavaLangThrowable())) + currentScope.problemReporter().unusedThrowableAllocation(this); + int pc = codeStream.position; ReferenceBinding allocatedType = this.codegenBinding.declaringClass; Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.236 diff -u -r1.236 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 14 Aug 2008 17:34:26 -0000 1.236 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 23 Aug 2008 09:40:56 -0000 @@ -601,6 +601,8 @@ 858 = The parameterized constructor <{3}>{0}({1}) of type {2} is not applicable for the arguments ({4}) 859 = The constructor {0}({1}) of raw type {2} is no longer generic; it cannot be parameterized with arguments <{3}> +888 = Allocating an instance of a throwable type, which is never used. Perhaps you meant to throw it? + ### ELABORATIONS ## Access restrictions 78592 = The type {1} is not accessible due to restriction on classpath entry {0} 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.374 diff -u -r1.374 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 14 Aug 2008 17:34:26 -0000 1.374 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 23 Aug 2008 09:40:54 -0000 @@ -318,6 +318,9 @@ case IProblem.ComparingIdentical: return CompilerOptions.ComparingIdentical; + + case IProblem.UnusedThrowableAllocation: + return CompilerOptions.UnusedThrowableAllocation; } return 0; } @@ -410,6 +413,7 @@ case (int)(CompilerOptions.FallthroughCase >>> 32): case (int)(CompilerOptions.OverridingMethodWithoutSuperInvocation >>> 32): case (int)(CompilerOptions.ComparingIdentical >>> 32): + case (int)(CompilerOptions.UnusedThrowableAllocation >>> 32): return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM; case (int)(CompilerOptions.TypeHiding >>> 32): @@ -7058,6 +7062,14 @@ typeDecl.sourceStart, typeDecl.sourceEnd); } +public void unusedThrowableAllocation(AllocationExpression allocationExpression) { + this.handle( + IProblem.UnusedThrowableAllocation, + NoArgument, + NoArgument, + allocationExpression.sourceStart, + allocationExpression.sourceEnd); +} public void unusedWarningToken(Expression token) { String[] arguments = new String[] { token.constant.stringValue() }; this.handle( 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.205 diff -u -r1.205 CompilerOptions.java --- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 27 Jun 2008 16:04:13 -0000 1.205 +++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 23 Aug 2008 09:40:42 -0000 @@ -120,6 +120,7 @@ public static final String OPTION_Process_Annotations = "org.eclipse.jdt.core.compiler.processAnnotations"; //$NON-NLS-1$ public static final String OPTION_ReportRedundantSuperinterface = "org.eclipse.jdt.core.compiler.problem.redundantSuperinterface"; //$NON-NLS-1$ public static final String OPTION_ReportComparingIdentical = "org.eclipse.jdt.core.compiler.problem.comparingIdentical"; //$NON-NLS-1$ + public static final String OPTION_ReportUnusedThrowableAllocation = "org.eclipse.jdt.core.compiler.problem.unusedThrowableAllocation"; //$NON-NLS-1$ // Backward compatibility public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$ @@ -215,6 +216,7 @@ public static final long UnusedWarningToken = ASTNode.Bit55L; public static final long RedundantSuperinterface = ASTNode.Bit56L; public static final long ComparingIdentical = ASTNode.Bit57L; + public static final long UnusedThrowableAllocation = ASTNode.Bit58L; // Map: String optionKey --> Long irritant> private static Map OptionToIrritants; @@ -251,7 +253,8 @@ | UnusedTypeArguments | NullReference | UnusedWarningToken - | ComparingIdentical; + | ComparingIdentical + | UnusedThrowableAllocation; // By default only lines and source attributes are generated. public int produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES; @@ -463,6 +466,7 @@ optionsMap.put(OPTION_Process_Annotations, this.processAnnotations ? ENABLED : DISABLED); optionsMap.put(OPTION_ReportRedundantSuperinterface, getSeverityString(RedundantSuperinterface)); optionsMap.put(OPTION_ReportComparingIdentical, getSeverityString(ComparingIdentical)); + optionsMap.put(OPTION_ReportUnusedThrowableAllocation, getSeverityString(UnusedThrowableAllocation)); return optionsMap; } @@ -595,6 +599,8 @@ return OPTION_ReportRedundantSuperinterface; case (int)(ComparingIdentical >>> 32) : return OPTION_ReportComparingIdentical; + case (int)(UnusedThrowableAllocation >>> 32) : + return OPTION_ReportUnusedThrowableAllocation; } } return null; @@ -884,6 +890,8 @@ if ((optionValue = optionsMap.get(OPTION_ReportUnusedTypeArgumentsForMethodInvocation)) != null) updateSeverity(UnusedTypeArguments, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportRedundantSuperinterface)) != null) updateSeverity(RedundantSuperinterface, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportComparingIdentical)) != null) updateSeverity(ComparingIdentical, optionValue); + if ((optionValue = optionsMap.get(OPTION_ReportUnusedThrowableAllocation)) != null) updateSeverity(UnusedThrowableAllocation, optionValue); + // Javadoc options if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) { @@ -1081,6 +1089,8 @@ buf.append("\n\t- unused type arguments for method/constructor invocation: ").append(getSeverityString(UnusedTypeArguments)); //$NON-NLS-1$ buf.append("\n\t- redundant superinterface: ").append(getSeverityString(RedundantSuperinterface)); //$NON-NLS-1$ buf.append("\n\t- comparing identical expr: ").append(getSeverityString(ComparingIdentical)); //$NON-NLS-1$ + buf.append("\n\t- unused instantiation of throwable: ").append(getSeverityString(UnusedThrowableAllocation)); //$NON-NLS-1$ + return buf.toString(); } @@ -1283,6 +1293,7 @@ case (int) (UnusedLabel >>> 32): case (int) (UnusedTypeArguments >>> 32) : case (int) (RedundantSuperinterface >>> 32) : + case (int) (UnusedThrowableAllocation >>> 32): return "unused"; //$NON-NLS-1$ case (int) (DiscouragedReference >>> 32) : case (int) (ForbiddenReference >>> 32) : @@ -1379,7 +1390,7 @@ break; case 'u' : if ("unused".equals(warningToken)) //$NON-NLS-1$ - return UnusedLocalVariable | UnusedArgument | UnusedPrivateMember | UnusedDeclaredThrownException | UnusedLabel | UnusedImport | UnusedTypeArguments | RedundantSuperinterface; + return UnusedLocalVariable | UnusedArgument | UnusedPrivateMember | UnusedDeclaredThrownException | UnusedLabel | UnusedImport | UnusedTypeArguments | RedundantSuperinterface | UnusedThrowableAllocation; if ("unchecked".equals(warningToken)) //$NON-NLS-1$ return UncheckedTypeOperation | RawTypeReference; if ("unqualified-field-access".equals(warningToken)) //$NON-NLS-1$ Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v retrieving revision 1.203 diff -u -r1.203 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 15 Aug 2008 14:50:43 -0000 1.203 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 23 Aug 2008 09:40:38 -0000 @@ -1303,6 +1303,9 @@ /** @since 3.1 */ int JavadocTypeArgumentsForRawGenericConstructor = Javadoc + Internal + 859; + /** @since 3.5 */ + int UnusedThrowableAllocation = Internal + 888; + /** * External problems -- These are problems defined by other plugins */