private static Field getOffsetField(Class<?> clazz) throws NoSuchFieldException {
      try {
        // up to jdk8 (which also has an "offset" field (we don't need) - therefore we check "parentOffset" first
        return clazz.getDeclaredField( "parentOffset" );
      } catch (NoSuchFieldException e) {
        // jdk9+ only has "offset" which is the parent offset
        return clazz.getDeclaredField( "offset" );
      }
    }
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