Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2016-06-28 09:26:15 +0000
committerManoj Palat2016-06-28 09:26:15 +0000
commit991dc7d1e96044f9ecf18ac597543b0270a6b791 (patch)
tree16a1d9e32c4d9e416c3187dc81cd7a08fd33884a
parent23da3645ea7a3db4dea8838527d8795348f824b8 (diff)
downloadeclipse.jdt.core-991dc7d1e96044f9ecf18ac597543b0270a6b791.tar.gz
eclipse.jdt.core-991dc7d1e96044f9ecf18ac597543b0270a6b791.tar.xz
eclipse.jdt.core-991dc7d1e96044f9ecf18ac597543b0270a6b791.zip
Fix for bug 488658 [1.9] Allow @SafeVarargs on private instance methods
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java44
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java3
2 files changed, 45 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java
index c1cabea5e6..2a969577a1 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java
@@ -4,7 +4,11 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contribution for
@@ -3736,4 +3740,42 @@ public class VarargsTest extends AbstractComparableTest {
},
"");
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=488658
+ public void testBug488658_001() throws Exception {
+ if (this.complianceLevel < ClassFileConstants.JDK9) return;
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "class Y<T> {}\n"+
+ "@SuppressWarnings(\"unused\")\n" +
+ "public class X {\n"+
+ " @SafeVarargs\n"+
+ " private <T> Y<T> foo(T ... a) {\n"+
+ " return null;\n"+
+ " }\n"+
+ "}\n",
+ },
+ "");
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class Y<T> {}\n"+
+ "public class X {\n"+
+ "@SuppressWarnings(\"unused\")\n" +
+ " private <T> Y<T> foo(T ... a) {\n"+
+ " return null;\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 4)\n" +
+ " private <T> Y<T> foo(T ... a) {\n" +
+ " ^\n" +
+ "Type safety: Potential heap pollution via varargs parameter a\n" +
+ "----------\n");
+
+ }
+
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index 3cb83038a1..71ae416e95 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -1949,7 +1949,8 @@ public MethodBinding resolveTypesFor(MethodBinding method) {
if ((method.tagBits & TagBits.AnnotationSafeVarargs) != 0) {
if (!method.isVarargs()) {
methodDecl.scope.problemReporter().safeVarargsOnFixedArityMethod(method);
- } else if (!method.isStatic() && !method.isFinal() && !method.isConstructor()) {
+ } else if (!method.isStatic() && !method.isFinal() && !method.isConstructor()
+ && !(sourceLevel >= ClassFileConstants.JDK9 && method.isPrivate())) {
methodDecl.scope.problemReporter().safeVarargsOnNonFinalInstanceMethod(method);
}
} else if (method.parameters != null && method.parameters.length > 0 && method.isVarargs()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795

Back to the top