Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 227313 Details for
Bug 400977
[1.8][compiler] Illegal combination of modifiers on interface methods produces confusing diagnostics
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed Patch
Fix-for-Bug-400977--18compiler-Interface-methods-are.patch (text/plain), 9.11 KB, created by
Manoj N Palat
on 2013-02-20 02:10:07 EST
(
hide
)
Description:
Proposed Patch
Filename:
MIME Type:
Creator:
Manoj N Palat
Created:
2013-02-20 02:10:07 EST
Size:
9.11 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultMethodsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultMethodsTest.java >index 889b7f0..8510463 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultMethodsTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultMethodsTest.java >@@ -57,10 +57,10 @@ > "@Target(ElementType.METHOD) @interface Annot{}\n" + > "public interface I {\n" + > " default void foo1() {}\n" + >- " public default synchronized void foo2() { System.exit(0); }\n" + >+ " public default void foo2() { System.exit(0); }\n" + > " strictfp default void foo3() {}\n" + >- " public default strictfp synchronized void foo4() {}\n" + >- " public default strictfp synchronized @Annot void foo5() {}\n" + >+ " public default strictfp void foo4() {}\n" + >+ " public default strictfp @Annot void foo5() {}\n" + > "}\n" + > "public class Wrong{}\n"}, // TODO remove me > // TODO remove me: >@@ -81,10 +81,10 @@ > "@Target(ElementType.METHOD) @interface Annot{}\n" + > "public interface I {\n" + > " default void foo1() { System.out.println(3); }\n" + >- " public default synchronized void foo2() {}\n" + >+ " public default void foo2() {}\n" + > " stritfp default void foo3() {}\n" + // typo in strictfp >- " default public strictfp synchronized void foo4() {}\n" + >- " public strictfp default synchronized @Annot void foo5() {}\n" + >+ " default public strictfp void foo4() {}\n" + >+ " public strictfp default @Annot void foo5() {}\n" + > " public default <T> T foo6(T t) { return t; }\n" + > "}\n"}, > "----------\n" + >@@ -169,22 +169,22 @@ > "3. ERROR in I.java (at line 4)\n" + > " native default void foo3() {}\n" + > " ^^^^^^\n" + >- "Illegal modifier for the interface method foo3; only public, abstract, strictfp & synchronized are permitted\n" + >+ "Illegal modifier for the interface method foo3; only public, abstract, strictfp, default & static are permitted\n" + > "----------\n" + > "4. ERROR in I.java (at line 5)\n" + > " default native void foo4() {}\n" + > " ^^^^^^\n" + >- "Illegal modifier for the interface method foo4; only public, abstract, strictfp & synchronized are permitted\n" + >+ "Illegal modifier for the interface method foo4; only public, abstract, strictfp, default & static are permitted\n" + > "----------\n" + > "5. ERROR in I.java (at line 6)\n" + > " static default void foo5() {}\n" + > " ^^^^^^\n" + >- "Illegal modifier for the interface method foo5; only public, abstract, strictfp & synchronized are permitted\n" + >+ "Illegal modifier for the interface method foo5; only public, abstract, strictfp, default & static are permitted\n" + > "----------\n" + > "6. ERROR in I.java (at line 7)\n" + > " default static void foo6() {}\n" + > " ^^^^^^\n" + >- "Illegal modifier for the interface method foo6; only public, abstract, strictfp & synchronized are permitted\n" + >+ "Illegal modifier for the interface method foo6; only public, abstract, strictfp, default & static are permitted\n" + > "----------\n"); > } > >@@ -220,7 +220,7 @@ > "4. ERROR in I.java (at line 7)\n" + > " abstract static default void foo5() {}\n" + > " ^^^^^^\n" + >- "Illegal modifier for the interface method foo5; only public, abstract, strictfp & synchronized are permitted\n" + >+ "Illegal modifier for the interface method foo5; only public, abstract, strictfp, default & static are permitted\n" + > "----------\n" + > "5. ERROR in I.java (at line 7)\n" + > " abstract static default void foo5() {}\n" + >@@ -323,6 +323,25 @@ > options); > } > >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=400977 >+ // test for error on synchronized >+ public void testModifiers400977() { >+ runNegativeTest( >+ new String[] { >+ "I.java", >+ "import java.lang.annotation.*;\n" + >+ "@Target(ElementType.METHOD) @interface Annot{}\n" + >+ "public interface I {\n" + >+ " synchronized default void foo() { System.out.println(3); }\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in I.java (at line 4)\n" + >+ " synchronized default void foo() { System.out.println(3); }\n" + >+ " ^^^^^\n" + >+ "Illegal modifier for the interface method foo; only public, abstract, strictfp, default & static are permitted\n" + >+ "----------\n"); >+ } >+ > // JLS 9.4.2 - default method cannot override method from Object > // Bug 382355 - [1.8][compiler] Compiler accepts erroneous default method > // new error message >diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java >index 51df8b6..b582f6e 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java >@@ -13860,4 +13860,21 @@ > "Name clash: The method m() of type Foo has the same erasure as m() of type Y but does not override it\n" + > "----------\n"); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400977 >+// test for error message on synchronized on non default method >+public void testModifiersNonDefault400977() { >+ runNegativeTest( >+ new String[] { >+ "I.java", >+ "public interface I {\n" + >+ " synchronized void foo();\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in I.java (at line 2)\n" + >+ " synchronized void foo();\n" + >+ " ^^^^^\n" + >+ "Illegal modifier for the interface method foo; only public & abstract are permitted\n" + >+ "----------\n"); >+} > } >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java >index fdd3474..ffc4eae 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2012 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -177,12 +177,14 @@ > // set the requested modifiers for a method in an interface/annotation > if (declaringClass.isInterface()) { > int expectedModifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; >- // 9.4 got updated for JSR 335 (default methods), more permissive grammar plus: >- // "It is a compile-time error if an abstract method declaration contains either of the keywords strictfp or synchronized." >- if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8 && !methodBinding.isAbstract()) { >- expectedModifiers |= (ClassFileConstants.AccSynchronized | ClassFileConstants.AccStrictfp); >+ boolean isDefaultMethod = false; // makes sense only >= 1.8 >+ if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) { >+ // 9.4 got updated for JSR 335 (default methods), more permissive grammar plus: >+ // "It is a compile-time error if an abstract method declaration contains the keyword strictfp" >+ if (!methodBinding.isAbstract()) >+ expectedModifiers |= ClassFileConstants.AccStrictfp ; >+ isDefaultMethod = (modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0; // no need to check validity, is done by the parser > } >- boolean isDefaultMethod = (modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0; // no need to check validity, is done by the parser > if ((realModifiers & ~expectedModifiers) != 0) { > if ((declaringClass.modifiers & ClassFileConstants.AccAnnotation) != 0) > problemReporter().illegalModifierForAnnotationMember((AbstractMethodDeclaration) this.referenceContext); >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties >index 1cb2d92..d9740b2 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties >@@ -771,7 +771,7 @@ > > # Default methods: > # variant of 359: >-1050 = Illegal modifier for the interface method {0}; only public, abstract, strictfp & synchronized are permitted >+1050 = Illegal modifier for the interface method {0}; only public, abstract, strictfp, default & static are permitted > 1051 = A default method cannot override a method from java.lang.Object > 1052 = The default method {0} inherited from {1} conflicts with another method inherited from {2} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 400977
:
227313
|
232421
|
232426
|
233362