Bug 537593 Eclipse cannot make up its mind if there is synthetic access
code involved or not
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
index d5a27a8e..68d61a4 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
@@ -11866,4 +11866,95 @@
assertEquals(1, requestor.problemArguments.length);
assertEquals(JavaCore.COMPILER_PB_UNUSED_PARAMETER, requestor.problemArguments[0]);
}
+public void testBug537593_001() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_8)
+ return;
+ class MyCompilerRequestor implements ICompilerRequestor {
+ String[] problemArguments = null;
+
+ @Override
+ public void acceptResult(CompilationResult result) {
+ for (CategorizedProblem problem : result.getAllProblems()) {
+ String[] arguments = problem.getArguments();
+ if (arguments != null && arguments.length > 0) {
+ this.problemArguments = arguments;
+ return;
+ }
+ }
+ }
+ }
+
+ if (this.complianceLevel <= ClassFileConstants.JDK1_5) {
+ return;
+ }
+ String[] files = new String[] {
+ "X.java",
+ "\n" +
+ "public class X {\n" +
+ "\n" +
+ " protected void bar(Z z) {\n" +
+ " System.out.println(z.toString());\n" +
+ " }\n" +
+ "\n" +
+ " public void foo() {\n" +
+ " bar(() -> {\n" +
+ " foo2(new I() {\n" +
+ " @SuppressWarnings({\"unused\"})\n" +
+ " public void bar2() {}\n" +
+ " });\n" +
+ " });\n" +
+ " }\n" +
+ " public static void main(String[] args) {}\n" +
+ "\n" +
+ " public Z foo2(I i) {\n" +
+ " return i == null ? null : null;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "interface Z {\n" +
+ " void apply();\n" +
+ "}\n" +
+ "\n" +
+ "interface I {}\n" +
+ "\n",
+ };
+
+ Map options = getCompilerOptions();
+ Object[] opts = {
+ CompilerOptions.OPTION_ReportUnusedDeclaredThrownException,
+ CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable,
+ CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference,
+ CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionWhenOverriding,
+ CompilerOptions.OPTION_ReportUnusedExceptionParameter,
+ CompilerOptions.OPTION_ReportUnusedImport,
+ CompilerOptions.OPTION_ReportUnusedLabel,
+ CompilerOptions.OPTION_ReportUnusedLocal,
+ CompilerOptions.OPTION_ReportUnusedObjectAllocation,
+ CompilerOptions.OPTION_ReportUnusedParameter,
+ CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete,
+ CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference,
+ CompilerOptions.OPTION_ReportUnusedPrivateMember,
+ CompilerOptions.OPTION_ReportUnusedTypeArgumentsForMethodInvocation,
+ CompilerOptions.OPTION_ReportUnusedTypeParameter,
+ CompilerOptions.OPTION_ReportUnusedWarningToken,
+ CompilerOptions.OPTION_ReportRedundantSuperinterface,
+ CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments,
+ };
+ for (Object option : opts)
+ options.put(option, CompilerOptions.WARNING);
+ MyCompilerRequestor requestor = new MyCompilerRequestor();
+ runTest(files,
+ false,
+ "",
+ "" /*expectedOutputString */,
+ "" /* expectedErrorString */,
+ false /* forceExecution */,
+ null /* classLib */,
+ true /* shouldFlushOutputDirectory */,
+ null /* vmArguments */,
+ options,
+ new Requestor(true, requestor, false, true),
+ JavacTestOptions.DEFAULT);
+ assertNull(requestor.problemArguments);
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java
index 02c0f51..9a86b92 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java
@@ -33,6 +33,7 @@
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
+import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.jdt.internal.compiler.parser.NLSTag;
@@ -553,8 +554,17 @@
this.stringLiterals[this.stringLiteralsPtr++] = literal;
}
-public void recordSuppressWarnings(IrritantSet irritants, Annotation annotation, int scopeStart, int scopeEnd, ReferenceContext context) {
+private boolean isLambdaExpressionCopyContext(ReferenceContext context) {
if (context instanceof LambdaExpression && context != ((LambdaExpression) context).original())
+ return true; // Do not record from copies. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=441929
+ Scope cScope = context instanceof AbstractMethodDeclaration ? ((AbstractMethodDeclaration) context).scope :
+ context instanceof TypeDeclaration ? ((TypeDeclaration) context).scope :
+ context instanceof LambdaExpression ? ((LambdaExpression) context).scope :
+ null;
+ return cScope != null ? isLambdaExpressionCopyContext(cScope.parent.referenceContext()) : false;
+}
+public void recordSuppressWarnings(IrritantSet irritants, Annotation annotation, int scopeStart, int scopeEnd, ReferenceContext context) {
+ if (isLambdaExpressionCopyContext(context))
return; // Do not record from copies. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=441929
if (this.suppressWarningIrritants == null) {