### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java,v retrieving revision 1.103 diff -u -r1.103 QualifiedAllocationExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 28 Jul 2011 17:07:04 -0000 1.103 +++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 22 Sep 2011 18:38:50 -0000 @@ -59,6 +59,11 @@ // analyse the enclosing instance if (this.enclosingInstance != null) { flowInfo = this.enclosingInstance.analyseCode(currentScope, flowContext, flowInfo); + } else { + if (this.binding.declaringClass.superclass().isMemberType() && !this.binding.declaringClass.superclass().isStatic()) { + // creating an anonymous type of a non-static member type without an enclosing instance of parent type + currentScope.resetEnclosingMethodStaticFlag(); + } } // check captured variables are initialized in current context (26134) #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java,v retrieving revision 1.44 diff -u -r1.44 ProblemTypeAndMethodTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java 28 Jul 2011 17:06:26 -0000 1.44 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java 22 Sep 2011 18:38:57 -0000 @@ -7076,4 +7076,39 @@ compilerOptions /* custom options */ ); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354502 +// Anonymous class instantiation of a non-static member type, method can't be static +public void test354502() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public abstract class Abstract{}\n" + + " public static abstract class Abstract2{}\n" + + " private void method1() {\n" + // don't warn + " new Abstract() {};\n" + + " }\n" + + " private void method2() {\n" + // warn + " new Abstract2() {};\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " private void method2() {\n" + + " ^^^^^^^^^\n" + + "The method method2() from the type X can be declared as static\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} }