View | Details | Raw Unified | Return to bug 354502
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java (+5 lines)
Lines 59-64 Link Here
59
		// analyse the enclosing instance
59
		// analyse the enclosing instance
60
		if (this.enclosingInstance != null) {
60
		if (this.enclosingInstance != null) {
61
			flowInfo = this.enclosingInstance.analyseCode(currentScope, flowContext, flowInfo);
61
			flowInfo = this.enclosingInstance.analyseCode(currentScope, flowContext, flowInfo);
62
		} else {
63
			if (this.binding.declaringClass.superclass().isMemberType() && !this.binding.declaringClass.superclass().isStatic()) {
64
				// creating an anonymous type of a non-static member type without an enclosing instance of parent type
65
				currentScope.resetEnclosingMethodStaticFlag();
66
			}
62
		}
67
		}
63
68
64
		// check captured variables are initialized in current context (26134)
69
		// check captured variables are initialized in current context (26134)
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java (+35 lines)
Lines 7076-7079 Link Here
7076
		compilerOptions /* custom options */
7076
		compilerOptions /* custom options */
7077
	);
7077
	);
7078
}
7078
}
7079
7080
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354502
7081
// Anonymous class instantiation of a non-static member type, method can't be static
7082
public void test354502() {
7083
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
7084
		return;
7085
	Map compilerOptions = getCompilerOptions();
7086
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
7087
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
7088
	compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE);
7089
	this.runNegativeTest(
7090
		new String[] {
7091
				"X.java", 
7092
				"public class X {\n" +
7093
				"   public abstract class Abstract{}\n" +
7094
				"   public static abstract class Abstract2{}\n" +
7095
				"	private void method1() {\n" + 	// don't warn
7096
				"		new Abstract() {};\n" +
7097
				"	}\n" +
7098
				"	private void method2() {\n" + 	// warn
7099
				"		new Abstract2() {};\n" +
7100
				"	}\n" +
7101
				"}"
7102
		},
7103
		"----------\n" + 
7104
		"1. ERROR in X.java (at line 7)\n" + 
7105
		"	private void method2() {\n" + 
7106
		"	             ^^^^^^^^^\n" + 
7107
		"The method method2() from the type X can be declared as static\n" + 
7108
		"----------\n",
7109
		null /* no extra class libraries */,
7110
		true /* flush output directory */,
7111
		compilerOptions /* custom options */
7112
	);
7113
}
7079
}
7114
}

Return to bug 354502