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 429906 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java (-1 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010, 2014 GK Software AG and others.
2
 * Copyright (c) 2010, 2014 GK Software AG, IBM 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 7102-7105 public void testBug430084() { Link Here
7102
		"Return type for the method is missing\n" +
7102
		"Return type for the method is missing\n" +
7103
		"----------\n");
7103
		"----------\n");
7104
}
7104
}
7105
7106
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=429906
7107
//[compiler][null] Array initializations not handled
7108
public void test429906() {
7109
	Map customOptions = getCompilerOptions();
7110
	String code =
7111
		"import org.eclipse.jdt.annotation.*;\n" +
7112
		"@NonNullByDefault\n" +
7113
		"public class X {\n" +
7114
		"	int[] a;\n" +
7115
		"	int[] d = { 2 };\n" +
7116
		"	X() {\n" +
7117
		"		a = new int[0];\n" +
7118
		"		foo(a);\n" +
7119
		"		foo(d);\n" +
7120
		"		int[] b = new int[0];\n" +
7121
		"		foo(b);\n" +
7122
		"		int [] c = { 2 };\n" +
7123
		"		foo(c);\n" +
7124
		"	}\n" +
7125
		"	void foo(int [] b) {}\n" +
7126
		"}\n";
7127
	runConformTestWithLibs(new String [] { "X.java", code }, customOptions, "");
7128
}
7105
}
7129
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java (+7 lines)
Lines 240-243 public class ArrayAllocationExpression extends Expression { Link Here
240
	public Annotation[][] getAnnotationsOnDimensions() {
240
	public Annotation[][] getAnnotationsOnDimensions() {
241
		return this.annotationsOnDimensions;
241
		return this.annotationsOnDimensions;
242
	}
242
	}
243
244
	public int nullStatus(FlowInfo flowInfo, FlowContext flowContext) {
245
		if (this.dimensions.length != 1 && this.annotationsOnDimensions == null)
246
			return FlowInfo.POTENTIALLY_NULL;
247
248
		return FlowInfo.NON_NULL;
249
	}
243
}
250
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NullAnnotationMatching.java (-2 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2013, 2014 GK Software AG and others.
2
 * Copyright (c) 2013, 2014 GK Software AG, IBM 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 128-134 public class NullAnnotationMatching { Link Here
128
				if (requiredType.dimensions() == providedType.dimensions()) {
128
				if (requiredType.dimensions() == providedType.dimensions()) {
129
					long[] providedDimsTagBits = ((ArrayBinding)providedType).nullTagBitsPerDimension;
129
					long[] providedDimsTagBits = ((ArrayBinding)providedType).nullTagBitsPerDimension;
130
					if (providedDimsTagBits == null) {
130
					if (providedDimsTagBits == null) {
131
						severity = 1; // required is annotated, provided not, need unchecked conversion
131
						for (int i=0; i <=dims; i++) {
132
							long requiredBits = validNullTagBits(requiredDimsTagBits[i]);
133
							if (i > 0)
134
								nullStatus = -1;
135
							severity = Math.max(severity, computeNullProblemSeverity(requiredBits, 0, nullStatus, strict));
136
							if (severity == 2)
137
								return NullAnnotationMatching.NULL_ANNOTATIONS_MISMATCH;
138
						}
132
					} else {
139
					} else {
133
						for (int i=0; i<=dims; i++) {
140
						for (int i=0; i<=dims; i++) {
134
							long requiredBits = validNullTagBits(requiredDimsTagBits[i]);
141
							long requiredBits = validNullTagBits(requiredDimsTagBits[i]);
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+4 lines)
Lines 9132-9137 public void nullityMismatch(Expression expression, TypeBinding providedType, Typ Link Here
9132
			nullityMismatchSpecdNullable(expression, requiredType, annotationName);
9132
			nullityMismatchSpecdNullable(expression, requiredType, annotationName);
9133
			return;
9133
			return;
9134
		}
9134
		}
9135
		if (expression instanceof ArrayAllocationExpression) {
9136
			nullityMismatchingTypeAnnotation(expression, providedType, requiredType, NullAnnotationMatching.NULL_ANNOTATIONS_UNCHECKED);
9137
			return;
9138
		}
9135
		nullityMismatchPotentiallyNull(expression, requiredType, annotationName);
9139
		nullityMismatchPotentiallyNull(expression, requiredType, annotationName);
9136
		return;
9140
		return;
9137
	}
9141
	}

Return to bug 429906