private static Field getParentField(Class clazz) throws NoSuchFieldException {
      try {
        // java 9+
        return clazz.getDeclaredField("root");
      } catch(NoSuchFieldException e) {
        return clazz.getDeclaredField("parent");
      }
    }
Supports sublists created via {@link ArrayList#subList(int, int)} since java7 and {@link LinkedList#subList(int, int)} since java9 (openjdk).
This is from kryo-serializers package.
ql/src/java/org/apache/hadoop/hive/ql/exec/SerializationUtilities.java