Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 400977 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultMethodsTest.java (-11 / +30 lines)
Lines 57-66 Link Here
57
			"@Target(ElementType.METHOD) @interface Annot{}\n" +
57
			"@Target(ElementType.METHOD) @interface Annot{}\n" +
58
			"public interface I {\n" +
58
			"public interface I {\n" +
59
			"    default void foo1()  {}\n" +
59
			"    default void foo1()  {}\n" +
60
			"    public default synchronized void foo2() { System.exit(0); }\n" +
60
			"    public default void foo2() { System.exit(0); }\n" +
61
			"    strictfp default void foo3() {}\n" +
61
			"    strictfp default void foo3() {}\n" +
62
			"    public default strictfp synchronized void foo4() {}\n" +
62
			"    public default strictfp void foo4() {}\n" +
63
			"    public default strictfp synchronized @Annot void foo5() {}\n" +
63
			"    public default strictfp @Annot void foo5() {}\n" +
64
			"}\n" +
64
			"}\n" +
65
			"public class Wrong{}\n"}, // TODO remove me
65
			"public class Wrong{}\n"}, // TODO remove me
66
		// TODO remove me:
66
		// TODO remove me:
Lines 81-90 Link Here
81
			"@Target(ElementType.METHOD) @interface Annot{}\n" +
81
			"@Target(ElementType.METHOD) @interface Annot{}\n" +
82
			"public interface I {\n" +
82
			"public interface I {\n" +
83
			"    default void foo1() { System.out.println(3); }\n" +
83
			"    default void foo1() { System.out.println(3); }\n" +
84
			"    public default synchronized void foo2() {}\n" +
84
			"    public default void foo2() {}\n" +
85
			"    stritfp default void foo3() {}\n" + // typo in strictfp
85
			"    stritfp default void foo3() {}\n" + // typo in strictfp
86
			"    default public strictfp synchronized void foo4() {}\n" +
86
			"    default public strictfp void foo4() {}\n" +
87
			"    public strictfp  default synchronized @Annot void foo5() {}\n" +
87
			"    public strictfp  default @Annot void foo5() {}\n" +
88
			"    public default <T> T foo6(T t) { return t; }\n" +
88
			"    public default <T> T foo6(T t) { return t; }\n" +
89
			"}\n"},
89
			"}\n"},
90
			"----------\n" +
90
			"----------\n" +
Lines 169-190 Link Here
169
			"3. ERROR in I.java (at line 4)\n" +
169
			"3. ERROR in I.java (at line 4)\n" +
170
			"	native default void foo3() {}\n" +
170
			"	native default void foo3() {}\n" +
171
			"	                    ^^^^^^\n" +
171
			"	                    ^^^^^^\n" +
172
			"Illegal modifier for the interface method foo3; only public, abstract, strictfp & synchronized are permitted\n" +
172
			"Illegal modifier for the interface method foo3; only public, abstract, strictfp, default & static are permitted\n" +
173
			"----------\n" +
173
			"----------\n" +
174
			"4. ERROR in I.java (at line 5)\n" +
174
			"4. ERROR in I.java (at line 5)\n" +
175
			"	default native void foo4() {}\n" +
175
			"	default native void foo4() {}\n" +
176
			"	                    ^^^^^^\n" +
176
			"	                    ^^^^^^\n" +
177
			"Illegal modifier for the interface method foo4; only public, abstract, strictfp & synchronized are permitted\n" +
177
			"Illegal modifier for the interface method foo4; only public, abstract, strictfp, default & static are permitted\n" +
178
			"----------\n" +
178
			"----------\n" +
179
			"5. ERROR in I.java (at line 6)\n" +
179
			"5. ERROR in I.java (at line 6)\n" +
180
			"	static default void foo5() {}\n" +
180
			"	static default void foo5() {}\n" +
181
			"	                    ^^^^^^\n" +
181
			"	                    ^^^^^^\n" +
182
			"Illegal modifier for the interface method foo5; only public, abstract, strictfp & synchronized are permitted\n" +
182
			"Illegal modifier for the interface method foo5; only public, abstract, strictfp, default & static are permitted\n" +
183
			"----------\n" +
183
			"----------\n" +
184
			"6. ERROR in I.java (at line 7)\n" +
184
			"6. ERROR in I.java (at line 7)\n" +
185
			"	default static void foo6() {}\n" +
185
			"	default static void foo6() {}\n" +
186
			"	                    ^^^^^^\n" +
186
			"	                    ^^^^^^\n" +
187
			"Illegal modifier for the interface method foo6; only public, abstract, strictfp & synchronized are permitted\n" +
187
			"Illegal modifier for the interface method foo6; only public, abstract, strictfp, default & static are permitted\n" +
188
			"----------\n");
188
			"----------\n");
189
	}
189
	}
190
190
Lines 220-226 Link Here
220
			"4. ERROR in I.java (at line 7)\n" +
220
			"4. ERROR in I.java (at line 7)\n" +
221
			"	abstract static default void foo5() {}\n" +
221
			"	abstract static default void foo5() {}\n" +
222
			"	                             ^^^^^^\n" +
222
			"	                             ^^^^^^\n" +
223
			"Illegal modifier for the interface method foo5; only public, abstract, strictfp & synchronized are permitted\n" +
223
			"Illegal modifier for the interface method foo5; only public, abstract, strictfp, default & static are permitted\n" +
224
			"----------\n" +
224
			"----------\n" +
225
			"5. ERROR in I.java (at line 7)\n" +
225
			"5. ERROR in I.java (at line 7)\n" +
226
			"	abstract static default void foo5() {}\n" +
226
			"	abstract static default void foo5() {}\n" +
Lines 323-328 Link Here
323
			options);
323
			options);
324
	}
324
	}
325
325
326
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400977
327
	// test for error on synchronized
328
	public void testModifiers400977() {
329
		runNegativeTest(
330
		new String[] {
331
			"I.java",
332
			"import java.lang.annotation.*;\n" +
333
			"@Target(ElementType.METHOD) @interface Annot{}\n" +
334
			"public interface I {\n" +
335
			"    synchronized default void foo() { System.out.println(3); }\n" +
336
			"}\n"},
337
			"----------\n" + 
338
			"1. ERROR in I.java (at line 4)\n" + 
339
			"	synchronized default void foo() { System.out.println(3); }\n" + 
340
			"	                          ^^^^^\n" + 
341
			"Illegal modifier for the interface method foo; only public, abstract, strictfp, default & static are permitted\n" + 
342
			"----------\n");
343
	}
344
326
	// JLS 9.4.2  - default method cannot override method from Object
345
	// JLS 9.4.2  - default method cannot override method from Object
327
	// Bug 382355 - [1.8][compiler] Compiler accepts erroneous default method
346
	// Bug 382355 - [1.8][compiler] Compiler accepts erroneous default method
328
	// new error message
347
	// new error message
(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (+17 lines)
Lines 13860-13863 Link Here
13860
		"Name clash: The method m() of type Foo has the same erasure as m() of type Y but does not override it\n" + 
13860
		"Name clash: The method m() of type Foo has the same erasure as m() of type Y but does not override it\n" + 
13861
		"----------\n");
13861
		"----------\n");
13862
}
13862
}
13863
13864
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400977
13865
// test for error message on synchronized on non default method
13866
public void testModifiersNonDefault400977() {
13867
	runNegativeTest(
13868
	new String[] {
13869
		"I.java",
13870
		"public interface I {\n" +
13871
		"    synchronized void foo();\n" +
13872
		"}\n"},
13873
		"----------\n" + 
13874
		"1. ERROR in I.java (at line 2)\n" + 
13875
		"	synchronized void foo();\n" + 
13876
		"	                  ^^^^^\n" + 
13877
		"Illegal modifier for the interface method foo; only public & abstract are permitted\n" + 
13878
		"----------\n");
13879
}
13863
}
13880
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java (-6 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 177-188 Link Here
177
	// set the requested modifiers for a method in an interface/annotation
177
	// set the requested modifiers for a method in an interface/annotation
178
	if (declaringClass.isInterface()) {
178
	if (declaringClass.isInterface()) {
179
		int expectedModifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
179
		int expectedModifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
180
		// 9.4 got updated for JSR 335 (default methods), more permissive grammar plus:
180
		boolean isDefaultMethod = false; // makes sense only >= 1.8
181
		// "It is a compile-time error if an abstract method declaration contains either of the keywords strictfp or synchronized."
181
		if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) {
182
		if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8 && !methodBinding.isAbstract()) {
182
			// 9.4 got updated for JSR 335 (default methods), more permissive grammar plus:
183
			expectedModifiers |= (ClassFileConstants.AccSynchronized | ClassFileConstants.AccStrictfp);
183
			// "It is a compile-time error if an abstract method declaration contains the keyword strictfp"
184
			if (!methodBinding.isAbstract()) 
185
				expectedModifiers |= ClassFileConstants.AccStrictfp ;
186
			isDefaultMethod = (modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0; // no need to check validity, is done by the parser
184
		}
187
		}
185
		boolean isDefaultMethod = (modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0; // no need to check validity, is done by the parser
186
		if ((realModifiers & ~expectedModifiers) != 0) {
188
		if ((realModifiers & ~expectedModifiers) != 0) {
187
			if ((declaringClass.modifiers & ClassFileConstants.AccAnnotation) != 0)
189
			if ((declaringClass.modifiers & ClassFileConstants.AccAnnotation) != 0)
188
				problemReporter().illegalModifierForAnnotationMember((AbstractMethodDeclaration) this.referenceContext);
190
				problemReporter().illegalModifierForAnnotationMember((AbstractMethodDeclaration) this.referenceContext);
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (-1 / +1 lines)
Lines 771-777 Link Here
771
771
772
# Default methods:
772
# Default methods:
773
# variant of 359: 
773
# variant of 359: 
774
1050 = Illegal modifier for the interface method {0}; only public, abstract, strictfp & synchronized are permitted
774
1050 = Illegal modifier for the interface method {0}; only public, abstract, strictfp, default & static are permitted
775
1051 = A default method cannot override a method from java.lang.Object 
775
1051 = A default method cannot override a method from java.lang.Object 
776
1052 = The default method {0} inherited from {1} conflicts with another method inherited from {2}
776
1052 = The default method {0} inherited from {1} conflicts with another method inherited from {2}
777
777

Return to bug 400977