private static boolean checkObjectGraphIdentityHashCodeCollision(Object obj,Set<Integer> counted,List<Integer> countedList) throws SecurityException {
  Stack<Object> stack=new Stack<>();
  stack.push(obj);
  while (!(stack.isEmpty())) {
    Object object=stack.pop();
    Integer identityHashCode=Integer.valueOf(System.identityHashCode(object));
    boolean added=counted.add(identityHashCode);
    if (!added) {
      if (!countedList.contains(identityHashCode)) {
        return false;
      }
    }
 else {
      Class<?> clazz=object.getClass();
      Class<?> compType=clazz.getComponentType();
      if ((compType != null) && (!(compType.isPrimitive()))) {
        Object[] array=(Object[])object;
        for (        Object element : array) {
          if (element != null) {
            stack.push(element);
          }
        }
      }
      while (clazz != null) {
        for (        Field field : clazz.getDeclaredFields()) {
          int mod=field.getModifiers();
          if ((mod & 0x8) == 0) {
            Class<?> fieldClass=field.getType();
            if (!(fieldClass.isPrimitive())) {
              if (!(field.isAccessible())) {
                field.setAccessible(true);
              }
              try {
                Object subObject=field.get(object);
                if (subObject != null) {
                  stack.push(subObject);
                }
              }
 catch (              IllegalAccessException illAcc) {
                throw new InternalError("Couldn't read " + field);
              }
            }
          }
        }
        clazz=clazz.getSuperclass();
      }
    }
  }
  return true;
}

private static boolean checkObjectGraphIdentityHashCodeCollision ( Object obj , Set < Integer > counted , List < Integer > countedList ) throws SecurityException { Stack < Object > stack = new Stack < > ( ) ; stack . push ( obj ) ; while ( ! ( stack . isEmpty ( ) ) ) { Object object = stack . pop ( ) ; Integer identityHashCode = Integer . valueOf ( System . identityHashCode ( object ) ) ; boolean added = counted . add ( identityHashCode ) ; if ( ! added ) { if ( ! countedList . contains ( identityHashCode ) ) { return false ; } } else { Class < ? > clazz = object . getClass ( ) ; Class < ? > compType = clazz . getComponentType ( ) ; if ( ( compType != null ) && ( ! ( compType . isPrimitive ( ) ) ) ) { Object [ ] array = ( Object [ ] ) object ; for ( Object element : array ) { if ( element != null ) { stack . push ( element ) ; } } } while ( clazz != null ) { for ( Field field : clazz . getDeclaredFields ( ) ) { int mod = field . getModifiers ( ) ; if ( ( mod & 0x8 ) == 0 ) { Class < ? > fieldClass = field . getType ( ) ; if ( ! ( fieldClass . isPrimitive ( ) ) ) { if ( ! ( field . isAccessible ( ) ) ) { field . setAccessible ( true ) ; } try { Object subObject = field . get ( object ) ; if ( subObject != null ) { stack . push ( subObject ) ; } } catch ( IllegalAccessException illAcc ) { throw new InternalError ( "Couldn't read " + field ) ; } } } } clazz = clazz . getSuperclass ( ) ; } } } return true ; }
checks for the possible object graph identity hash code collision . objects that don ' t pass this check can not be given to the classmexer for size calculations , because correct size will not be calculated due to the collision that will occur in the classmexer internally . < p > most of this method is copied by the classmexer .
