Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2017-04-08 21:23:32 +0000
committerTill Brychcy2017-04-08 21:27:02 +0000
commit0da3c2bfd41bdb1134fb297a803d154ee2ea7998 (patch)
treeb998ef531d0824fd45dc8990c55d47c9fecd4ddb
parent014c06267ac1095468f04c8ad5976b803ebd32b0 (diff)
downloadeclipse.jdt.core-0da3c2bfd41bdb1134fb297a803d154ee2ea7998.tar.gz
eclipse.jdt.core-0da3c2bfd41bdb1134fb297a803d154ee2ea7998.tar.xz
eclipse.jdt.core-0da3c2bfd41bdb1134fb297a803d154ee2ea7998.zip
Bug 514977 - [1.8][null] Arguments of varargs invocation are not always
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java77
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java4
2 files changed, 79 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
index 1a03907b17..6478082e3e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
@@ -15262,4 +15262,81 @@ public void testBug514570() {
""
);
}
+public void testBug514977() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "test/Test.java",
+ "package test;\n" +
+ "\n" +
+ "import org.eclipse.jdt.annotation.DefaultLocation;\n" +
+ "import org.eclipse.jdt.annotation.NonNull;\n" +
+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " static void nn(@NonNull Object i) {\n" +
+ " i.hashCode();\n" +
+ " }\n" +
+ "\n" +
+ " static void f(@NonNull Integer @NonNull... args) {\n" +
+ " nn(args);\n" +
+ " for (Integer s : args) {\n" +
+ " nn(s);\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " @NonNullByDefault({ DefaultLocation.ARRAY_CONTENTS, DefaultLocation.PARAMETER })\n" +
+ " static void g(Integer... args) {\n" +
+ " nn(args);\n" +
+ " for (Integer s : args) {\n" +
+ " nn(s);\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " Integer i = args.length == 0 ? null : 1;\n" +
+ " Integer[] array = i == null ? null : new Integer[] {i};\n" +
+ " f(array);\n" +
+ " f(i);\n" +
+ " f(1, i);\n" +
+ " g(array);\n" +
+ " g(i);\n" +
+ " g(1, i);\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. ERROR in test\\Test.java (at line 30)\n" +
+ " f(array);\n" +
+ " ^^^^^\n" +
+ "Null type mismatch: required \'@NonNull Integer @NonNull[]\' but the provided value is inferred as @Nullable\n" +
+ "----------\n" +
+ "2. ERROR in test\\Test.java (at line 31)\n" +
+ " f(i);\n" +
+ " ^\n" +
+ "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" +
+ "----------\n" +
+ "3. ERROR in test\\Test.java (at line 32)\n" +
+ " f(1, i);\n" +
+ " ^\n" +
+ "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" +
+ "----------\n" +
+ "4. ERROR in test\\Test.java (at line 33)\n" +
+ " g(array);\n" +
+ " ^^^^^\n" +
+ "Null type mismatch: required \'@NonNull Integer @NonNull[]\' but the provided value is inferred as @Nullable\n" +
+ "----------\n" +
+ "5. ERROR in test\\Test.java (at line 34)\n" +
+ " g(i);\n" +
+ " ^\n" +
+ "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" +
+ "----------\n" +
+ "6. ERROR in test\\Test.java (at line 35)\n" +
+ " g(1, i);\n" +
+ " ^\n" +
+ "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" +
+ "----------\n"
+ );
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java
index 52f0c52188..e3643f6436 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -125,8 +125,8 @@ protected void analyseArguments(BlockScope currentScope, FlowContext flowContext
if (methodBinding.isVarargs()) {
varArgPos = numParamsToCheck-1;
// this if-block essentially copied from generateArguments(..):
+ varArgsType = methodBinding.parameters[varArgPos];
if (numParamsToCheck == arguments.length) {
- varArgsType = methodBinding.parameters[varArgPos];
TypeBinding lastType = arguments[varArgPos].resolvedType;
if (lastType == TypeBinding.NULL
|| (varArgsType.dimensions() == lastType.dimensions()

Back to the top