import java.util.*; public class D { public static List p; void init() { List l = new ArrayList(); p = l; } void f() { int n = p == null ? 0 : p.size(); for (int i = 0; i < n; i++) { Object o = p.get(i); // OK } } public static class MyList extends ArrayList { @Override public int size() { p = new ArrayList(); return super.size(); } } }