Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShankha Banerjee2013-05-08 05:13:29 +0000
committerssankaran2013-05-08 05:13:29 +0000
commit1c82ab4ca7a7921e02eb1c1295505414f94bc64d (patch)
treea6536448746cb4559d5d42e5f08d8c3e61268f5e
parente586991bacf22cb0c88410f0cd529579715fb06a (diff)
downloadeclipse.jdt.core-1c82ab4ca7a7921e02eb1c1295505414f94bc64d.tar.gz
eclipse.jdt.core-1c82ab4ca7a7921e02eb1c1295505414f94bc64d.tar.xz
eclipse.jdt.core-1c82ab4ca7a7921e02eb1c1295505414f94bc64d.zip
Fixed Bug 406619 - [1.8][compiler] Incorrect suggestion that method can
be made static.
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java21
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java2
2 files changed, 22 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
index c9f04f94df..5ec8f8788e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
@@ -18,6 +18,7 @@ package org.eclipse.jdt.core.tests.compiler.regression;
import java.util.Map;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import junit.framework.Test;
@@ -1742,6 +1743,26 @@ public class InterfaceMethodsTest extends AbstractComparableTest {
"Cannot use super in a static context\n" +
"----------\n");
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=406619, [1.8][compiler] Incorrect suggestion that method can be made static.
+ public void test406619() {
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface X {\n" +
+ " default int foo() {\n" +
+ " return 10;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "",
+ null /* no extra class libraries */,
+ true /* flush output directory */,
+ compilerOptions /* custom options */
+ );
+ }
// class implements interface with default method.
// - synth. access needed for visibility reasons
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
index c68500dd4e..f6aacc792e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
@@ -145,7 +145,7 @@ public class MethodDeclaration extends AbstractMethodDeclaration {
// check unused parameters
this.scope.checkUnusedParameters(this.binding);
// check if the method could have been static
- if (!this.binding.isStatic() && (this.bits & ASTNode.CanBeStatic) != 0) {
+ if (!this.binding.isStatic() && (this.bits & ASTNode.CanBeStatic) != 0 && !this.isDefaultMethod()) {
if(!this.binding.isOverriding() && !this.binding.isImplementing()) {
if (this.binding.isPrivate() || this.binding.isFinal() || this.binding.declaringClass.isFinal()) {
this.scope.problemReporter().methodCanBeDeclaredStatic(this);

Back to the top