code: public static Object getEnclosingInstance(final Object target) throws IllegalAccessException {
          if (target == null)
              throw new IllegalArgumentException("Target must not be null!");
  
          final Class<?> targetClass = target.getClass();
          if (isStatic(targetClass.getModifiers()) || !targetClass.isMemberClass())
              return null;
  
          final Class<?> enclosingClass = targetClass.getEnclosingClass();
          for (final Field field : targetClass.getDeclaredFields()) {
              if (field.getType().equals(enclosingClass)) {
                  field.setAccessible(true);
                  return field.get(target);
              }
          }
  
          throw new IllegalStateException("Member instance has no field containing the enclosing instance!");
      }
docs: Returns the {@link Object} that encloses the given {@code target}. This method returns {@code null} if the given
  {@code target} is null or its {@link Class} is not a member class.
  
  @param target the {@link Object} to retrieve the enclosing instance for
  @return the enclosing {@link Object} of {@code target}
  @throws IllegalArgumentException If {@code target} is {@code null}.
  @throws IllegalAccessException An instance of the enclosing class is kept in a private field within the enclosed
  instance. Accessing the field might throw an {@link IllegalAccessException}.
  @throws IllegalStateException If no field containing the enclosing instance can be found.