import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
class ArrayInitializerLength {
void testDeclaration() {
String[] arr = {"foo"};
if(arr.length == 2) {
System.out.println("oops");
}
}
void testNewExpression() {
String[] arr = new String[]{"foo"};
if(arr.length == 2) {
System.out.println("oops");
}
}
void testDimension() {
int[] arr = new int[3];
if(arr.length == 1) {
System.out.println("oops");
}
}
void testConditional() {
int[] arr = Math.random() > 0.5 ? new int[2] : new int[4];
if(arr.length == 3) {
System.out.println("never");
}
if(arr.length == 2) {
System.out.println("possible");
}
}
void testMultiDimensional() {
int[][][] arr = (new int[1][2][3]);
if(arr.length == 1) {
System.out.println("ok");
}
if(arr.length == 2) {
System.out.println("not ok");
}
if(arr.length == 3) {
System.out.println("not ok");
}
}
void testExecutionOrder(Object obj) {
if(obj instanceof String) {
// should not warn about possible CCE
obj = new String[] {(String)obj};
}
System.out.println(obj);
}
void test2DArray() {
int[][] md = {{1, 2, 3}, {3, 4}};
if(Math.random() > 0.5) {
int elem = md[1][2];
}
int[] subArray = md[0];
if (subArray.length == 3) {
System.out.println("Always");
}
}
}