View | Details | Raw Unified | Return to bug 365662
Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
2
 * Copyright (c) 2006, 2012 IBM Corporation 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 397-402 Link Here
397
		expectedProblemAttributes.put("CodeCannotBeReached", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
397
		expectedProblemAttributes.put("CodeCannotBeReached", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
398
		expectedProblemAttributes.put("CodeSnippetMissingClass", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
398
		expectedProblemAttributes.put("CodeSnippetMissingClass", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
399
		expectedProblemAttributes.put("CodeSnippetMissingMethod", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
399
		expectedProblemAttributes.put("CodeSnippetMissingMethod", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
400
		expectedProblemAttributes.put("ContradictoryNullAnnotations", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
400
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
401
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
401
		expectedProblemAttributes.put("ConflictingImport", new ProblemAttributes(CategorizedProblem.CAT_IMPORT));
402
		expectedProblemAttributes.put("ConflictingImport", new ProblemAttributes(CategorizedProblem.CAT_IMPORT));
402
		expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
403
		expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
Lines 790-795 Link Here
790
		expectedProblemAttributes.put("RedundantSpecificationOfTypeArguments", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
791
		expectedProblemAttributes.put("RedundantSpecificationOfTypeArguments", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
791
		expectedProblemAttributes.put("RedundantLocalVariableNullAssignment", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
792
		expectedProblemAttributes.put("RedundantLocalVariableNullAssignment", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
792
		expectedProblemAttributes.put("RedundantNullAnnotation", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
793
		expectedProblemAttributes.put("RedundantNullAnnotation", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
794
		expectedProblemAttributes.put("RedundantNullDefaultAnnotation", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
795
		expectedProblemAttributes.put("RedundantNullDefaultAnnotationPackage", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
796
		expectedProblemAttributes.put("RedundantNullDefaultAnnotationType", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
797
		expectedProblemAttributes.put("RedundantNullDefaultAnnotationMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
793
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
798
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
794
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullMessageSend", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
799
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullMessageSend", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
795
		expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
800
		expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
Lines 1089-1094 Link Here
1089
		expectedProblemAttributes.put("CodeSnippetMissingMethod", SKIP);
1094
		expectedProblemAttributes.put("CodeSnippetMissingMethod", SKIP);
1090
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL));
1095
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL));
1091
		expectedProblemAttributes.put("ConflictingImport", SKIP);
1096
		expectedProblemAttributes.put("ConflictingImport", SKIP);
1097
		expectedProblemAttributes.put("ContradictoryNullAnnotations", SKIP);
1092
		expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST));
1098
		expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST));
1093
		expectedProblemAttributes.put("CorruptedSignature", SKIP);
1099
		expectedProblemAttributes.put("CorruptedSignature", SKIP);
1094
		expectedProblemAttributes.put("DeadCode", new ProblemAttributes(JavaCore.COMPILER_PB_DEAD_CODE));
1100
		expectedProblemAttributes.put("DeadCode", new ProblemAttributes(JavaCore.COMPILER_PB_DEAD_CODE));
Lines 1480-1485 Link Here
1480
		expectedProblemAttributes.put("RedundantSpecificationOfTypeArguments", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_TYPE_ARGUMENTS));
1486
		expectedProblemAttributes.put("RedundantSpecificationOfTypeArguments", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_TYPE_ARGUMENTS));
1481
		expectedProblemAttributes.put("RedundantLocalVariableNullAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
1487
		expectedProblemAttributes.put("RedundantLocalVariableNullAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
1482
		expectedProblemAttributes.put("RedundantNullAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION));
1488
		expectedProblemAttributes.put("RedundantNullAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION));
1489
		expectedProblemAttributes.put("RedundantNullDefaultAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION));
1490
		expectedProblemAttributes.put("RedundantNullDefaultAnnotationPackage", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION));
1491
		expectedProblemAttributes.put("RedundantNullDefaultAnnotationType", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION));
1492
		expectedProblemAttributes.put("RedundantNullDefaultAnnotationMethod", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION));
1483
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
1493
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
1484
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullMessageSend", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
1494
		expectedProblemAttributes.put("RedundantNullCheckOnNonNullMessageSend", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
1485
		expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
1495
		expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java (-5 / +257 lines)
Lines 53-59 Link Here
53
// Static initializer to specify tests subset using TESTS_* static variables
53
// Static initializer to specify tests subset using TESTS_* static variables
54
// All specified tests which do not belong to the class are skipped...
54
// All specified tests which do not belong to the class are skipped...
55
static {
55
static {
56
//		TESTS_NAMES = new String[] { "test_default_nullness_014" };
56
//		TESTS_NAMES = new String[] { "test_redundant_annotation_" };
57
//		TESTS_NUMBERS = new int[] { 561 };
57
//		TESTS_NUMBERS = new int[] { 561 };
58
//		TESTS_RANGE = new int[] { 1, 2049 };
58
//		TESTS_RANGE = new int[] { 1, 2049 };
59
}
59
}
Lines 2537-2542 Link Here
2537
		"	new C(null);\n" + 
2537
		"	new C(null);\n" + 
2538
		"	      ^^^^\n" + 
2538
		"	      ^^^^\n" + 
2539
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
2539
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
2540
		"----------\n" + 
2541
		"----------\n" + 
2542
		"1. WARNING in p1\\C.java (at line 2)\n" + 
2543
		"	@org.eclipse.jdt.annotation.NonNullByDefault\n" + 
2544
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
2545
		"Nullness default is redundant with a default specified for the enclosing package p1\n" + 
2540
		"----------\n");
2546
		"----------\n");
2541
}
2547
}
2542
// Bug 365836 - [compiler][null] Incomplete propagation of null defaults.
2548
// Bug 365836 - [compiler][null] Incomplete propagation of null defaults.
Lines 2654-2659 Link Here
2654
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
2660
		"Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + 
2655
		"----------\n");
2661
		"----------\n");
2656
}
2662
}
2663
2664
// redundant default annotations - class vs. inner class
2665
public void test_redundant_annotation_01() {
2666
	Map customOptions = getCompilerOptions();
2667
//	customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR);
2668
	runConformTestWithLibs(
2669
		new String[] {
2670
			"p2/Y.java",
2671
			"package p2;\n" +
2672
			"import org.eclipse.jdt.annotation.*;\n" +
2673
			"@NonNullByDefault\n" +
2674
			"public class Y {\n" +
2675
			"    @NonNullByDefault class Inner {\n" +
2676
			"        @NonNullByDefault class DeepInner {}\n" +
2677
			"    }\n" +
2678
			"    class Inner2 {\n" +
2679
			"        @NonNullByDefault class DeepInner2 {\n" +
2680
			"        }\n" +
2681
			"        void foo() {\n" +
2682
			"            @SuppressWarnings(\"unused\") @NonNullByDefault class Local {}\n" +
2683
			"        }\n" +
2684
			"    }\n" +
2685
			"}\n" +
2686
			"@NonNullByDefault class V {}\n",
2687
			"p3/package-info.java",
2688
			"@org.eclipse.jdt.annotation.NonNullByDefault package p3;\n",
2689
			"p3/Z.java",
2690
			"package p3;\n" +
2691
			"import org.eclipse.jdt.annotation.*;\n" +
2692
			"@NonNullByDefault\n" +
2693
			"public class Z {\n" +
2694
			"}\n" +
2695
			"class X {\n" +
2696
			"    @NonNullByDefault class Inner {}\n" +
2697
			"    class Inner2 {\n" +
2698
			"        @NonNullByDefault class DeepInner {}\n" +
2699
			"    }\n" +
2700
			"}\n"
2701
		},
2702
		customOptions,
2703
		"----------\n" + 
2704
		"1. WARNING in p2\\Y.java (at line 5)\n" +
2705
		"	@NonNullByDefault class Inner {\n" +
2706
		"	^^^^^^^^^^^^^^^^^\n" +
2707
		"Nullness default is redundant with a default specified for the enclosing type Y\n" +
2708
		"----------\n" +
2709
		"2. WARNING in p2\\Y.java (at line 6)\n" +
2710
		"	@NonNullByDefault class DeepInner {}\n" +
2711
		"	^^^^^^^^^^^^^^^^^\n" +
2712
		"Nullness default is redundant with a default specified for the enclosing type Y.Inner\n" +
2713
		"----------\n" +
2714
		"3. WARNING in p2\\Y.java (at line 9)\n" +
2715
		"	@NonNullByDefault class DeepInner2 {\n" +
2716
		"	^^^^^^^^^^^^^^^^^\n" +
2717
		"Nullness default is redundant with a default specified for the enclosing type Y\n" +
2718
		"----------\n" +
2719
		"4. WARNING in p2\\Y.java (at line 12)\n" +
2720
		"	@SuppressWarnings(\"unused\") @NonNullByDefault class Local {}\n" +
2721
		"	                            ^^^^^^^^^^^^^^^^^\n" +
2722
		"Nullness default is redundant with a default specified for the enclosing type Y\n" +
2723
		"----------\n" +
2724
		"----------\n" +
2725
		"1. WARNING in p3\\Z.java (at line 3)\n" +
2726
		"	@NonNullByDefault\n" +
2727
		"	^^^^^^^^^^^^^^^^^\n" +
2728
		"Nullness default is redundant with a default specified for the enclosing package p3\n" +
2729
		"----------\n" +
2730
		"2. WARNING in p3\\Z.java (at line 7)\n" +
2731
		"	@NonNullByDefault class Inner {}\n" +
2732
		"	^^^^^^^^^^^^^^^^^\n" +
2733
		"Nullness default is redundant with a default specified for the enclosing package p3\n" +
2734
		"----------\n" +
2735
		"3. WARNING in p3\\Z.java (at line 9)\n" +
2736
		"	@NonNullByDefault class DeepInner {}\n" +
2737
		"	^^^^^^^^^^^^^^^^^\n" +
2738
		"Nullness default is redundant with a default specified for the enclosing package p3\n" +
2739
		"----------\n");
2740
}
2741
// redundant default annotations - class vs. method
2742
public void test_redundant_annotation_02() {
2743
	Map customOptions = getCompilerOptions();
2744
	runConformTestWithLibs(
2745
		new String[] {
2746
			"p2/Y.java",
2747
			"package p2;\n" +
2748
			"import org.eclipse.jdt.annotation.*;\n" +
2749
			"@NonNullByDefault\n" +
2750
			"public class Y {\n" +
2751
			"    @NonNullByDefault void foo() {}\n" +
2752
			"}\n" +
2753
			"class Z {\n" +
2754
			"    @NonNullByDefault void bar() {\n" +
2755
			"         @NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" +
2756
			"             @NonNullByDefault void fubar() {}\n" +
2757
			"         }\n" +
2758
			"    }\n" +
2759
			"    @NonNullByDefault void zink() {\n" +
2760
			"         @SuppressWarnings(\"unused\") class Bork {\n" +
2761
			"             @NonNullByDefault void jubar() {}\n" +
2762
			"         }\n" +
2763
			"    }\n" +
2764
			"}\n"
2765
		},
2766
		customOptions,
2767
		"----------\n" +
2768
		"1. WARNING in p2\\Y.java (at line 5)\n" +
2769
		"	@NonNullByDefault void foo() {}\n" +
2770
		"	^^^^^^^^^^^^^^^^^\n" +
2771
		"Nullness default is redundant with a default specified for the enclosing type Y\n" +
2772
		"----------\n" +
2773
		"2. WARNING in p2\\Y.java (at line 9)\n" +
2774
		"	@NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" +
2775
		"	^^^^^^^^^^^^^^^^^\n" +
2776
		"Nullness default is redundant with a default specified for the enclosing method bar()\n" +
2777
		"----------\n" +
2778
		"3. WARNING in p2\\Y.java (at line 10)\n" +
2779
		"	@NonNullByDefault void fubar() {}\n" +
2780
		"	^^^^^^^^^^^^^^^^^\n" +
2781
		"Nullness default is redundant with a default specified for the enclosing type Zork\n" +
2782
		"----------\n" +
2783
		"4. WARNING in p2\\Y.java (at line 15)\n" +
2784
		"	@NonNullByDefault void jubar() {}\n" +
2785
		"	^^^^^^^^^^^^^^^^^\n" +
2786
		"Nullness default is redundant with a default specified for the enclosing method zink()\n" +
2787
		"----------\n");
2788
}
2789
//redundant default annotations - class vs. method - generics
2790
public void test_redundant_annotation_02g() {
2791
	Map customOptions = getCompilerOptions();
2792
	runConformTestWithLibs(
2793
		new String[] {
2794
			"p2/Y.java",
2795
			"package p2;\n" +
2796
			"import org.eclipse.jdt.annotation.*;\n" +
2797
			"@NonNullByDefault\n" +
2798
			"public class Y<TY> {\n" +
2799
			"    @NonNullByDefault <TF> void foo(TF arg) {}\n" +
2800
			"}\n" +
2801
			"class Z {\n" +
2802
			"    @NonNullByDefault <TB> void bar() {\n" +
2803
			"         @NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" +
2804
			"             @NonNullByDefault void fubar(TB arg) {}\n" +
2805
			"         }\n" +
2806
			"    }\n" +
2807
			"}\n"
2808
		},
2809
		customOptions,
2810
		"----------\n" + 
2811
		"1. WARNING in p2\\Y.java (at line 5)\n" + 
2812
		"	@NonNullByDefault <TF> void foo(TF arg) {}\n" + 
2813
		"	^^^^^^^^^^^^^^^^^\n" + 
2814
		"Nullness default is redundant with a default specified for the enclosing type Y<TY>\n" + 
2815
		"----------\n" + 
2816
		"2. WARNING in p2\\Y.java (at line 9)\n" + 
2817
		"	@NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" + 
2818
		"	^^^^^^^^^^^^^^^^^\n" + 
2819
		"Nullness default is redundant with a default specified for the enclosing method bar()\n" + 
2820
		"----------\n" + 
2821
		"3. WARNING in p2\\Y.java (at line 10)\n" + 
2822
		"	@NonNullByDefault void fubar(TB arg) {}\n" + 
2823
		"	^^^^^^^^^^^^^^^^^\n" + 
2824
		"Nullness default is redundant with a default specified for the enclosing type Zork\n" + 
2825
		"----------\n");
2826
}
2827
2828
// redundant default annotations - package / class / method vs global default
2829
public void test_redundant_annotation_03() {
2830
	Map customOptions = getCompilerOptions();
2831
	customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED);
2832
	runConformTestWithLibs(
2833
		new String[] {
2834
			"p2/Y.java",
2835
			"package p2;\n" +
2836
			"import org.eclipse.jdt.annotation.*;\n" +
2837
			"@NonNullByDefault\n" +
2838
			"public class Y {\n" +
2839
			"    @NonNullByDefault void foo() {}\n" +
2840
			"}\n" +
2841
			"class Z {\n" +
2842
			"    @NonNullByDefault void bar() {}\n" +
2843
			"}\n",
2844
			"p3/package-info.java",
2845
			"@org.eclipse.jdt.annotation.NonNullByDefault package p3;\n"
2846
		},
2847
		customOptions,
2848
		"----------\n" + 
2849
		"1. WARNING in p2\\Y.java (at line 3)\n" +
2850
		"	@NonNullByDefault\n" +
2851
		"	^^^^^^^^^^^^^^^^^\n" +
2852
		"Nullness default is redundant with the global default\n" +
2853
		"----------\n" +
2854
		"2. WARNING in p2\\Y.java (at line 5)\n" +
2855
		"	@NonNullByDefault void foo() {}\n" +
2856
		"	^^^^^^^^^^^^^^^^^\n" +
2857
		"Nullness default is redundant with a default specified for the enclosing type Y\n" +
2858
		"----------\n" +
2859
		"3. WARNING in p2\\Y.java (at line 8)\n" +
2860
		"	@NonNullByDefault void bar() {}\n" +
2861
		"	^^^^^^^^^^^^^^^^^\n" +
2862
		"Nullness default is redundant with the global default\n" +
2863
		"----------\n" +
2864
		"----------\n" +
2865
		"1. WARNING in p3\\package-info.java (at line 1)\n" +
2866
		"	@org.eclipse.jdt.annotation.NonNullByDefault package p3;\n" +
2867
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
2868
		"Nullness default is redundant with the global default\n" +
2869
		"----------\n");
2870
}
2871
2872
// contradictory null annotations
2873
public void test_contradictory_annotations_01() {
2874
	Map customOptions = getCompilerOptions();
2875
	runNegativeTestWithLibs(
2876
		new String[] {
2877
			"p2/Y.java",
2878
			"package p2;\n" +
2879
			"import org.eclipse.jdt.annotation.*;\n" +
2880
			"public class Y {\n" +
2881
			"    void foo(@NonNull @Nullable Object o) {}\n" +
2882
			"    @Nullable @NonNull Object bar() {\n" +
2883
			"        @NonNull @Nullable Object o = null;\n" +
2884
			"        return o;\n" +
2885
			"    }\n" +
2886
			"}\n" +
2887
			"class Z {\n" +
2888
			"    @NonNullByDefault void bar() {}\n" +
2889
			"}\n"
2890
		},
2891
		customOptions,
2892
		"----------\n" + 
2893
		"1. ERROR in p2\\Y.java (at line 4)\n" + 
2894
		"	void foo(@NonNull @Nullable Object o) {}\n" + 
2895
		"	                  ^^^^^^^^^\n" + 
2896
		"Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + 
2897
		"----------\n" + 
2898
		"2. ERROR in p2\\Y.java (at line 5)\n" + 
2899
		"	@Nullable @NonNull Object bar() {\n" + 
2900
		"	          ^^^^^^^^\n" + 
2901
		"Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + 
2902
		"----------\n" + 
2903
		"3. ERROR in p2\\Y.java (at line 6)\n" + 
2904
		"	@NonNull @Nullable Object o = null;\n" + 
2905
		"	         ^^^^^^^^^\n" + 
2906
		"Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + 
2907
		"----------\n");
2908
}
2909
2657
// a nonnull variable is dereferenced in a loop
2910
// a nonnull variable is dereferenced in a loop
2658
public void test_nonnull_var_in_constrol_structure_1() {
2911
public void test_nonnull_var_in_constrol_structure_1() {
2659
	Map customOptions = getCompilerOptions();
2912
	Map customOptions = getCompilerOptions();
Lines 2915-2921 Link Here
2915
		customOptions,
3168
		customOptions,
2916
		"");	
3169
		"");	
2917
}
3170
}
2918
// a nonnull variable is dereferenced method of a nested type
3171
// a nonnull variable is dereferenced in a method of a nested type
2919
public void test_nesting_1() {
3172
public void test_nesting_1() {
2920
	Map customOptions = getCompilerOptions();
3173
	Map customOptions = getCompilerOptions();
2921
//	customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR);
3174
//	customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR);
Lines 2924-2930 Link Here
2924
		new String[] {
3177
		new String[] {
2925
			"X.java",
3178
			"X.java",
2926
			"import org.eclipse.jdt.annotation.*;\n" +
3179
			"import org.eclipse.jdt.annotation.*;\n" +
2927
			"@NonNullByDefault\n" +
2928
			"public class X {\n" +
3180
			"public class X {\n" +
2929
			"    void print4(final String s1) {\n" +
3181
			"    void print4(final String s1) {\n" +
2930
			"        for (int i=0; i<3; i++)\n" +
3182
			"        for (int i=0; i<3; i++)\n" +
Lines 2959-2970 Link Here
2959
		},
3211
		},
2960
		customOptions,
3212
		customOptions,
2961
		"----------\n" +
3213
		"----------\n" +
2962
		"1. ERROR in X.java (at line 16)\n" +
3214
		"1. ERROR in X.java (at line 15)\n" +
2963
		"	print(s2);\n" +
3215
		"	print(s2);\n" +
2964
		"	      ^^\n" +
3216
		"	      ^^\n" +
2965
		"Type mismatch: required \'@NonNull String\' but the provided value can be null\n" +
3217
		"Type mismatch: required \'@NonNull String\' but the provided value can be null\n" +
2966
		"----------\n" +
3218
		"----------\n" +
2967
		"2. ERROR in X.java (at line 25)\n" +
3219
		"2. ERROR in X.java (at line 24)\n" +
2968
		"	@NonNull String s3R = s3;\n" +
3220
		"	@NonNull String s3R = s3;\n" +
2969
		"	                      ^^\n" +
3221
		"	                      ^^\n" +
2970
		"Type mismatch: required \'@NonNull String\' but the provided value can be null\n" +
3222
		"Type mismatch: required \'@NonNull String\' but the provided value can be null\n" +
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation 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 1460-1465 Link Here
1460
	int RedundantNullAnnotation = MethodRelated + 922;
1460
	int RedundantNullAnnotation = MethodRelated + 922;
1461
	/** @since 3.8 */
1461
	/** @since 3.8 */
1462
	int IllegalAnnotationForBaseType = TypeRelated + 923;
1462
	int IllegalAnnotationForBaseType = TypeRelated + 923;
1463
	/** @since 3.8 */
1464
	int RedundantNullDefaultAnnotation = Internal + 925;
1465
	/** @since 3.8 */
1466
	int RedundantNullDefaultAnnotationPackage = Internal + 926;
1467
	/** @since 3.8 */
1468
	int RedundantNullDefaultAnnotationType = Internal + 927;
1469
	/** @since 3.8 */
1470
	int RedundantNullDefaultAnnotationMethod = Internal + 928;
1471
	/** @since 3.8 */
1472
	int ContradictoryNullAnnotations = Internal + 929;
1463
1473
1464
	/**
1474
	/**
1465
	 * External problems -- These are problems defined by other plugins
1475
	 * External problems -- These are problems defined by other plugins
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java (+10 lines)
Lines 25-30 Link Here
25
public abstract class Annotation extends Expression {
25
public abstract class Annotation extends Expression {
26
26
27
	final static MemberValuePair[] NoValuePairs = new MemberValuePair[0];
27
	final static MemberValuePair[] NoValuePairs = new MemberValuePair[0];
28
	private static final long TAGBITS_NULLABLE_OR_NONNULL = TagBits.AnnotationNullable|TagBits.AnnotationNonNull;
29
28
	public int declarationSourceEnd;
30
	public int declarationSourceEnd;
29
	public Binding recipient;
31
	public Binding recipient;
30
32
Lines 387-392 Link Here
387
							AbstractMethodDeclaration methodDeclaration = sourceType.scope.referenceContext.declarationOf(sourceMethod);
389
							AbstractMethodDeclaration methodDeclaration = sourceType.scope.referenceContext.declarationOf(sourceMethod);
388
							recordSuppressWarnings(scope, methodDeclaration.declarationSourceStart, methodDeclaration.declarationSourceEnd, scope.compilerOptions().suppressWarnings);
390
							recordSuppressWarnings(scope, methodDeclaration.declarationSourceStart, methodDeclaration.declarationSourceEnd, scope.compilerOptions().suppressWarnings);
389
						}
391
						}
392
						if ((sourceMethod.tagBits & TAGBITS_NULLABLE_OR_NONNULL) == TAGBITS_NULLABLE_OR_NONNULL) {
393
							scope.problemReporter().contradictoryNullAnnotations(this);
394
							sourceMethod.tagBits &= ~TAGBITS_NULLABLE_OR_NONNULL; // avoid secondary problems
395
						}
390
						break;
396
						break;
391
					case Binding.FIELD :
397
					case Binding.FIELD :
392
						FieldBinding sourceField = (FieldBinding) this.recipient;
398
						FieldBinding sourceField = (FieldBinding) this.recipient;
Lines 404-409 Link Here
404
							 LocalDeclaration localDeclaration = variable.declaration;
410
							 LocalDeclaration localDeclaration = variable.declaration;
405
							recordSuppressWarnings(scope, localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd, scope.compilerOptions().suppressWarnings);
411
							recordSuppressWarnings(scope, localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd, scope.compilerOptions().suppressWarnings);
406
						}
412
						}
413
						if ((variable.tagBits & TAGBITS_NULLABLE_OR_NONNULL) == TAGBITS_NULLABLE_OR_NONNULL) {
414
							scope.problemReporter().contradictoryNullAnnotations(this);
415
							variable.tagBits &= ~TAGBITS_NULLABLE_OR_NONNULL; // avoid secondary problems
416
						}
407
						break;
417
						break;
408
				}
418
				}
409
			}
419
			}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java (-1 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation 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 13-18 Link Here
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
14
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
15
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.Annotation;
16
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
17
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
17
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
18
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
18
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
19
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
Lines 85-90 Link Here
85
	return this.superclass; // default answer
86
	return this.superclass; // default answer
86
}
87
}
87
88
89
protected void checkRedundantNullnessDefaultRecurse(ASTNode location, Annotation[] annotations, long annotationTagBits) {
90
	long outerDefault = this.enclosingMethod != null ? this.enclosingMethod.tagBits & ((TagBits.AnnotationNonNullByDefault|TagBits.AnnotationNullUnspecifiedByDefault)) : 0;
91
	if (outerDefault != 0) {
92
		if (outerDefault == annotationTagBits) {
93
			this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, this.enclosingMethod);
94
		}
95
		return;
96
	}
97
	super.checkRedundantNullnessDefaultRecurse(location, annotations, annotationTagBits);
98
}
99
88
public char[] computeUniqueKey(boolean isLeaf) {
100
public char[] computeUniqueKey(boolean isLeaf) {
89
	char[] outerKey = outermostEnclosingType().computeUniqueKey(isLeaf);
101
	char[] outerKey = outermostEnclosingType().computeUniqueKey(isLeaf);
90
	int semicolon = CharOperation.lastIndexOf(';', outerKey);
102
	int semicolon = CharOperation.lastIndexOf(';', outerKey);
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java (-1 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation 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 570-575 Link Here
570
			AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(originalMethod);
570
			AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(originalMethod);
571
			if (methodDecl != null)
571
			if (methodDecl != null)
572
				ASTNode.resolveAnnotations(methodDecl.scope, methodDecl.annotations, originalMethod);
572
				ASTNode.resolveAnnotations(methodDecl.scope, methodDecl.annotations, originalMethod);
573
			long nullDefaultBits = this.tagBits & (TagBits.AnnotationNonNullByDefault|TagBits.AnnotationNullUnspecifiedByDefault);
574
			if (nullDefaultBits != 0 && this.declaringClass instanceof SourceTypeBinding) {
575
				SourceTypeBinding declaringSourceType = (SourceTypeBinding) this.declaringClass;
576
				if (declaringSourceType.checkRedundantNullnessDefaultOne(methodDecl, methodDecl.annotations, nullDefaultBits)) {
577
					declaringSourceType.checkRedundantNullnessDefaultRecurse(methodDecl, methodDecl.annotations, nullDefaultBits);
578
				}
579
			}
573
		}
580
		}
574
	}
581
	}
575
	return originalMethod.tagBits;
582
	return originalMethod.tagBits;
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/NestedTypeBinding.java (-1 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation 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 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
14
import org.eclipse.jdt.internal.compiler.ast.Annotation;
12
15
13
public class NestedTypeBinding extends SourceTypeBinding {
16
public class NestedTypeBinding extends SourceTypeBinding {
14
17
Lines 107-112 Link Here
107
	return synthLocal;
110
	return synthLocal;
108
}
111
}
109
112
113
protected void checkRedundantNullnessDefaultRecurse(ASTNode location, Annotation[] annotations, long annotationTagBits) {
114
	ReferenceBinding currentType = this.enclosingType;
115
	do {
116
		if (!((SourceTypeBinding)currentType).checkRedundantNullnessDefaultOne(location, annotations, annotationTagBits)) {
117
			return;
118
		}
119
		currentType = currentType.enclosingType();
120
	} while (currentType instanceof SourceTypeBinding);
121
	super.checkRedundantNullnessDefaultRecurse(location, annotations, annotationTagBits);
122
}
123
110
/* Answer the receiver's enclosing type... null if the receiver is a top level type.
124
/* Answer the receiver's enclosing type... null if the receiver is a top level type.
111
*/
125
*/
112
public ReferenceBinding enclosingType() {
126
public ReferenceBinding enclosingType() {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (+37 lines)
Lines 23-28 Link Here
23
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
23
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
24
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
24
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
25
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
25
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
26
import org.eclipse.jdt.internal.compiler.ast.Annotation;
26
import org.eclipse.jdt.internal.compiler.ast.Argument;
27
import org.eclipse.jdt.internal.compiler.ast.Argument;
27
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
28
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
28
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
29
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
Lines 1636-1646 Link Here
1636
	if (defaultAnnotation != null) {
1637
	if (defaultAnnotation != null) {
1637
		if (CharOperation.equals(this.sourceName, TypeConstants.PACKAGE_INFO_NAME)) {
1638
		if (CharOperation.equals(this.sourceName, TypeConstants.PACKAGE_INFO_NAME)) {
1638
			getPackage().nullnessDefaultAnnotation = defaultAnnotation;
1639
			getPackage().nullnessDefaultAnnotation = defaultAnnotation;
1640
			long globalDefault = this.scope.compilerOptions().defaultNonNullness;
1641
			if (globalDefault == TagBits.AnnotationNonNull && (annotationTagBits & TagBits.AnnotationNonNullByDefault) != 0) {
1642
				TypeDeclaration typeDecl = this.scope.referenceContext;
1643
				this.scope.problemReporter().nullDefaultAnnotationIsRedundant(typeDecl, typeDecl.annotations, null);
1644
			}
1639
		} else {
1645
		} else {
1640
			this.nullnessDefaultAnnotation = defaultAnnotation;
1646
			this.nullnessDefaultAnnotation = defaultAnnotation;
1647
			TypeDeclaration typeDecl = this.scope.referenceContext;
1648
			long nullDefaultBits = annotationTagBits & (TagBits.AnnotationNullUnspecifiedByDefault|TagBits.AnnotationNonNullByDefault);
1649
			checkRedundantNullnessDefaultRecurse(typeDecl, typeDecl.annotations, nullDefaultBits);
1641
		}
1650
		}
1642
	}
1651
	}
1643
}
1652
}
1653
1654
protected void checkRedundantNullnessDefaultRecurse(ASTNode location, Annotation[] annotations, long annotationTagBits) {
1655
	if (this.fPackage.nullnessDefaultAnnotation != null) {
1656
		if ((this.fPackage.nullnessDefaultAnnotation.id == TypeIds.T_ConfiguredAnnotationNonNull
1657
				&& ((annotationTagBits & TagBits.AnnotationNonNullByDefault) != 0))) {
1658
			this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, this.fPackage);
1659
		}
1660
		return;
1661
	}
1662
	long globalDefault = this.scope.compilerOptions().defaultNonNullness;
1663
	if (globalDefault == TagBits.AnnotationNonNull && annotationTagBits == TagBits.AnnotationNonNullByDefault) {
1664
		this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, null);
1665
	}
1666
}
1667
1668
// return: should caller continue searching?
1669
protected boolean checkRedundantNullnessDefaultOne(ASTNode location, Annotation[] annotations, long annotationTagBits) {
1670
	TypeBinding thisDefault = this.nullnessDefaultAnnotation;
1671
	if (thisDefault != null) {
1672
		if (thisDefault.id == TypeIds.T_ConfiguredAnnotationNonNull
1673
			&& ((annotationTagBits & TagBits.AnnotationNonNullByDefault) != 0)) {
1674
			this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, this);
1675
		}
1676
		return false; // different default means inner default is not redundant -> we're done
1677
	}
1678
	return true;
1679
}
1680
1644
private TypeBinding getNullnessDefaultAnnotation() {
1681
private TypeBinding getNullnessDefaultAnnotation() {
1645
	if (this.nullnessDefaultAnnotation instanceof UnresolvedReferenceBinding)
1682
	if (this.nullnessDefaultAnnotation instanceof UnresolvedReferenceBinding)
1646
		this.nullnessDefaultAnnotation = this.scope.environment().getNullAnnotationResolved(this.nullnessDefaultAnnotation, this.scope);
1683
		this.nullnessDefaultAnnotation = this.scope.environment().getNullAnnotationResolved(this.nullnessDefaultAnnotation, this.scope);
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-8 / +53 lines)
Lines 96-101 Link Here
96
import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
96
import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
97
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
97
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
98
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
98
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
99
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
99
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
100
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
100
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
101
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
101
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
102
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
Lines 316-321 Link Here
316
		case IProblem.RequiredNonNullButProvidedUnknown:
317
		case IProblem.RequiredNonNullButProvidedUnknown:
317
			return CompilerOptions.NullSpecInsufficientInfo;
318
			return CompilerOptions.NullSpecInsufficientInfo;
318
		case IProblem.RedundantNullAnnotation:
319
		case IProblem.RedundantNullAnnotation:
320
		case IProblem.RedundantNullDefaultAnnotation:
321
		case IProblem.RedundantNullDefaultAnnotationPackage:
322
		case IProblem.RedundantNullDefaultAnnotationType:
323
		case IProblem.RedundantNullDefaultAnnotationMethod:
319
			return CompilerOptions.RedundantNullAnnotation;
324
			return CompilerOptions.RedundantNullAnnotation;
320
325
321
		case IProblem.BoxingConversion :
326
		case IProblem.BoxingConversion :
Lines 8182-8188 Link Here
8182
		.append(inheritedMethod.shortReadableName());
8187
		.append(inheritedMethod.shortReadableName());
8183
	int sourceStart = methodDecl.returnType.sourceStart;
8188
	int sourceStart = methodDecl.returnType.sourceStart;
8184
	Annotation[] annotations = methodDecl.annotations;
8189
	Annotation[] annotations = methodDecl.annotations;
8185
	sourceStart = findAnnotationSourceStart(annotations, sourceStart, TypeIds.T_ConfiguredAnnotationNullable);
8190
	Annotation annotation = findAnnotation(annotations, TypeIds.T_ConfiguredAnnotationNullable);
8191
	if (annotation != null) {
8192
		sourceStart = annotation.sourceStart;
8193
	}
8186
	this.handle(
8194
	this.handle(
8187
		IProblem.IllegalReturnNullityRedefinition, 
8195
		IProblem.IllegalReturnNullityRedefinition, 
8188
		new String[] { methodSignature.toString(), CharOperation.toString(nonNullAnnotationName)},
8196
		new String[] { methodSignature.toString(), CharOperation.toString(nonNullAnnotationName)},
Lines 8242-8248 Link Here
8242
	int sourceStart, sourceEnd;
8250
	int sourceStart, sourceEnd;
8243
	if (i == -1) {
8251
	if (i == -1) {
8244
		MethodDeclaration methodDecl = (MethodDeclaration) sourceMethod;
8252
		MethodDeclaration methodDecl = (MethodDeclaration) sourceMethod;
8245
		sourceStart = findAnnotationSourceStart(methodDecl.annotations, methodDecl.returnType.sourceStart, TypeIds.T_ConfiguredAnnotationNonNull);
8253
		Annotation annotation = findAnnotation(methodDecl.annotations, TypeIds.T_ConfiguredAnnotationNonNull);
8254
		sourceStart = annotation != null ? annotation.sourceStart : methodDecl.returnType.sourceStart;
8246
		sourceEnd = methodDecl.returnType.sourceEnd;
8255
		sourceEnd = methodDecl.returnType.sourceEnd;
8247
	} else {
8256
	} else {
8248
		Argument arg = sourceMethod.arguments[i];
8257
		Argument arg = sourceMethod.arguments[i];
Lines 8252-8281 Link Here
8252
	this.handle(IProblem.RedundantNullAnnotation, ProblemHandler.NoArgument, ProblemHandler.NoArgument, sourceStart, sourceEnd);
8261
	this.handle(IProblem.RedundantNullAnnotation, ProblemHandler.NoArgument, ProblemHandler.NoArgument, sourceStart, sourceEnd);
8253
}
8262
}
8254
8263
8264
public void nullDefaultAnnotationIsRedundant(ASTNode location, Annotation[] annotations, Binding outer) {
8265
	Annotation annotation = findAnnotation(annotations, TypeIds.T_ConfiguredAnnotationNonNullByDefault);
8266
	int start = annotation != null ? annotation.sourceStart : location.sourceStart;
8267
	int end = annotation != null ? annotation.sourceEnd : location.sourceStart;
8268
	String[] args = NoArgument;
8269
	String[] shortArgs = NoArgument;
8270
	if (outer != null) {
8271
		args = new String[] { new String(outer.readableName()) };
8272
		shortArgs = new String[] { new String(outer.shortReadableName()) };
8273
	}
8274
	int problemId = IProblem.RedundantNullDefaultAnnotation;
8275
	if (outer instanceof PackageBinding) {
8276
		problemId = IProblem.RedundantNullDefaultAnnotationPackage;
8277
	} else if (outer instanceof ReferenceBinding) {
8278
		problemId = IProblem.RedundantNullDefaultAnnotationType;
8279
	} else if (outer instanceof MethodBinding) {
8280
		problemId = IProblem.RedundantNullDefaultAnnotationMethod;
8281
	}
8282
	this.handle(problemId, args, shortArgs, start, end);
8283
}
8284
8285
public void contradictoryNullAnnotations(Annotation annotation) {
8286
	// when this error is triggered we can safely assume that both annotations have been configured
8287
	char[][] nonNullAnnotationName = this.options.nonNullAnnotationName;
8288
	char[][] nullableAnnotationName = this.options.nullableAnnotationName;
8289
	String[] arguments = {
8290
		new String(CharOperation.concatWith(nonNullAnnotationName, '.')),
8291
		new String(CharOperation.concatWith(nullableAnnotationName, '.'))
8292
	};
8293
	String[] shortArguments = {
8294
			new String(nonNullAnnotationName[nonNullAnnotationName.length-1]),
8295
			new String(nullableAnnotationName[nullableAnnotationName.length-1])
8296
		};
8297
	this.handle(IProblem.ContradictoryNullAnnotations, arguments, shortArguments, annotation.sourceStart, annotation.sourceEnd);
8298
}
8299
8255
public void illegalAnnotationForBaseType(TypeReference type, Annotation[] annotations, char[] annotationName, long nullAnnotationTagBit)
8300
public void illegalAnnotationForBaseType(TypeReference type, Annotation[] annotations, char[] annotationName, long nullAnnotationTagBit)
8256
{
8301
{
8257
	int typeId = (nullAnnotationTagBit == TagBits.AnnotationNullable) 
8302
	int typeId = (nullAnnotationTagBit == TagBits.AnnotationNullable) 
8258
			? TypeIds.T_ConfiguredAnnotationNullable : TypeIds.T_ConfiguredAnnotationNonNull;
8303
			? TypeIds.T_ConfiguredAnnotationNullable : TypeIds.T_ConfiguredAnnotationNonNull;
8259
	String[] args = new String[] { new String(annotationName), new String(type.getLastToken()) };
8304
	String[] args = new String[] { new String(annotationName), new String(type.getLastToken()) };
8305
	Annotation annotation = findAnnotation(annotations, typeId);
8306
	int start = annotation != null ? annotation.sourceStart : type.sourceStart;
8260
	this.handle(IProblem.IllegalAnnotationForBaseType,
8307
	this.handle(IProblem.IllegalAnnotationForBaseType,
8261
			args,
8308
			args,
8262
			args,
8309
			args,
8263
			findAnnotationSourceStart(annotations, type.sourceStart, typeId),
8310
			start,
8264
			type.sourceEnd);
8311
			type.sourceEnd);
8265
}
8312
}
8266
8313
8267
private int findAnnotationSourceStart(Annotation[] annotations, int startFallback, int typeId) {
8314
private Annotation findAnnotation(Annotation[] annotations, int typeId) {
8268
	int sourceStart = startFallback;
8269
	if (annotations != null) {
8315
	if (annotations != null) {
8270
		// should have a @NonNull/@Nullable annotation, search for it:
8316
		// should have a @NonNull/@Nullable annotation, search for it:
8271
		int length = annotations.length;
8317
		int length = annotations.length;
8272
		for (int j=0; j<length; j++) {
8318
		for (int j=0; j<length; j++) {
8273
			if (annotations[j].resolvedType != null && annotations[j].resolvedType.id == typeId) {
8319
			if (annotations[j].resolvedType != null && annotations[j].resolvedType.id == typeId) {
8274
				sourceStart = annotations[j].sourceStart;
8320
				return annotations[j];
8275
				break;
8276
			}
8321
			}
8277
		}
8322
		}
8278
	}
8323
	}
8279
	return sourceStart;
8324
	return null;
8280
}
8325
}
8281
}
8326
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+5 lines)
Lines 671-676 Link Here
671
921 = The method {0} from {1} cannot implement the corresponding method from {2} due to incompatible nullness constraints
671
921 = The method {0} from {1} cannot implement the corresponding method from {2} due to incompatible nullness constraints
672
922 = The nullness annotation is redundant with a default that applies to this location
672
922 = The nullness annotation is redundant with a default that applies to this location
673
923 = The nullness annotation @{0} is not applicable for the primitive type {1}
673
923 = The nullness annotation @{0} is not applicable for the primitive type {1}
674
925 = Nullness default is redundant with the global default
675
926 = Nullness default is redundant with a default specified for the enclosing package {0}
676
927 = Nullness default is redundant with a default specified for the enclosing type {0}
677
928 = Nullness default is redundant with a default specified for the enclosing method {0}
678
929 = Contradictory null specification; only one of @{0} and @{1} can be specified at any location
674
679
675
### ELABORATIONS
680
### ELABORATIONS
676
## Access restrictions
681
## Access restrictions

Return to bug 365662