1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
import org.checkerframework.checker.nullness.qual.*;
/*
* The test checks annotations in multidimention arrays.
* Each array dimention is beeing annotated with eather @Nullable or @NonNull
* to check error is thrown if assignment type is incompatible on eather
* array level.
* Tests uses 3 dimentional arrays. Each annotaion combination is used once starting
* with @Nullable [] @Nullable [] @Nullable [] and
* ends with @NonNull [] @NonNull [] @NonNull [].
*
* Test has 8 methods that returns 3-dimentional arrays where each dimention is annotated
* with eather @Nullable or @NonNull.
*
* Test containg 8 methods where all variables are beeing assign with one of arrays from
* method that returns annotated arrays.
*
* Errors are expected if one or more array levels in a declaration are annotated with @NonNull, but
* in assignment are annotated with @Nullable.
*/
public class MultidimentionalArrayAnnotationTest {
int numb = 1;
// Declared 8 3-dimentional variables.
Object @Nullable [] @Nullable [] @Nullable [] obj1 = new Object[numb][numb][numb];
Object @NonNull [] @Nullable [] @Nullable [] obj2 = new Object[numb][numb][numb];
Object @Nullable [] @NonNull [] @Nullable [] obj3 = new Object[numb][numb][numb];
Object @Nullable [] @Nullable [] @NonNull [] obj4 = new Object[numb][numb][numb];
Object @NonNull [] @NonNull [] @Nullable [] obj5 = new Object[numb][numb][numb];
Object @NonNull [] @Nullable [] @NonNull [] obj6 = new Object[numb][numb][numb];
Object @Nullable [] @NonNull [] @NonNull [] obj7 = new Object[numb][numb][numb];
Object @NonNull [] @NonNull [] @NonNull [] obj8 = new Object[numb][numb][numb];
/*
* Call to method 1 that returns Object @NonNull [] @NonNull [] @NonNull [].
* Errors are not expected.
*/
void callTomethod1() {
obj1 = method1();
obj2 = method1();
obj3 = method1();
obj4 = method1();
obj5 = method1();
obj6 = method1();
obj7 = method1();
obj8 = method1();
;
}
/*
* Call to method 2 that returns Object @Nullable [] @NonNull [] @NonNull [].
*/
void callTomethod2() {
obj1 = method2();
// :: error: (assignment.type.incompatible)
obj2 = method2();
obj3 = method2();
obj4 = method2();
// :: error: (assignment.type.incompatible)
obj5 = method2();
// :: error: (assignment.type.incompatible)
obj6 = method2();
obj7 = method2();
// :: error: (assignment.type.incompatible)
obj8 = method2();
}
/*
* Call to method 3 that returns Object @NonNull [] @Nullable [] @NonNull [].
*/
void callTomethod3() {
obj1 = method3();
obj2 = method3();
// :: error: (assignment.type.incompatible)
obj3 = method3();
obj4 = method3();
// :: error: (assignment.type.incompatible)
obj5 = method3();
obj6 = method3();
// :: error: (assignment.type.incompatible)
obj7 = method3();
// :: error: (assignment.type.incompatible)
obj8 = method3();
}
/*
* Call to method 4 that returns Object @NonNull [] @NonNull [] @Nullable [].
*/
void callTomethod4() {
obj1 = method4();
obj2 = method4();
obj3 = method4();
// :: error: (assignment.type.incompatible)
obj4 = method4();
obj5 = method4();
// :: error: (assignment.type.incompatible)
obj6 = method4();
// :: error: (assignment.type.incompatible)
obj7 = method4();
// :: error: (assignment.type.incompatible)
obj8 = method4();
}
/*
* Call to method 5 that returns Object @Nullable [] @Nullable [] @NonNull [].
*/
void callTomethod5() {
obj1 = method5();
// :: error: (assignment.type.incompatible)
obj2 = method5();
// :: error: (assignment.type.incompatible)
obj3 = method5();
obj4 = method5();
// :: error: (assignment.type.incompatible)
obj5 = method5();
// :: error: (assignment.type.incompatible)
obj6 = method5();
// :: error: (assignment.type.incompatible)
obj7 = method5();
// :: error: (assignment.type.incompatible)
obj8 = method5();
}
/*
* Call to method 6 that returns Object @Nullable [] @NonNull [] @Nullable [].
*/
void callTomethod6() {
obj1 = method6();
// :: error: (assignment.type.incompatible)
obj2 = method6();
obj3 = method6();
// :: error: (assignment.type.incompatible)
obj4 = method6();
// :: error: (assignment.type.incompatible)
obj5 = method6();
// :: error: (assignment.type.incompatible)
obj6 = method6();
// :: error: (assignment.type.incompatible)
obj7 = method6();
// :: error: (assignment.type.incompatible)
obj8 = method6();
}
/*
* Call to method 7 that returns Object @NonNull [] @Nullable [] @Nullable [].
*/
void callTomethod7() {
obj1 = method7();
obj2 = method7();
// :: error: (assignment.type.incompatible)
obj3 = method7();
// :: error: (assignment.type.incompatible)
obj4 = method7();
// :: error: (assignment.type.incompatible)
obj5 = method7();
// :: error: (assignment.type.incompatible)
obj6 = method7();
// :: error: (assignment.type.incompatible)
obj7 = method7();
// :: error: (assignment.type.incompatible)
obj8 = method7();
}
/*
* Call to method 8 that returns Object @Nullable [] @Nullable [] @Nullable [].
*/
void callTomethod8() {
obj1 = method8();
// :: error: (assignment.type.incompatible)
obj2 = method8();
// :: error: (assignment.type.incompatible)
obj3 = method8();
// :: error: (assignment.type.incompatible)
obj4 = method8();
// :: error: (assignment.type.incompatible)
obj5 = method8();
// :: error: (assignment.type.incompatible)
obj6 = method8();
// :: error: (assignment.type.incompatible)
obj7 = method8();
// :: error: (assignment.type.incompatible)
obj8 = method8();
}
Object[][][] method1() {
return new Object[numb][numb][numb];
};
Object @Nullable [][][] method2() {
return new Object[numb][numb][numb];
};
Object[] @Nullable [][] method3() {
return new Object[numb][numb][numb];
};
Object[][] @Nullable [] method4() {
return new Object[numb][numb][numb];
};
Object @Nullable [] @Nullable [][] method5() {
return new Object[numb][numb][numb];
};
Object @Nullable [][] @Nullable [] method6() {
return new Object[numb][numb][numb];
};
Object[] @Nullable [] @Nullable [] method7() {
return new Object[numb][numb][numb];
};
Object @Nullable [] @Nullable [] @Nullable [] method8() {
return new Object[numb][numb][numb];
};
}
|