code: public static void ensureMemberAccess(Class<?> currentClass,
                                            Class<?> memberClass,
                                            Object target,
                                            int modifiers)
          throws IllegalAccessException
      {
          if (target == null && Modifier.isProtected(modifiers)) {
              int mods = modifiers;
              mods = mods & (~Modifier.PROTECTED);
              mods = mods | Modifier.PUBLIC;
  
              /*
               * See if we fail because of class modifiers
               */
              Reflection.ensureMemberAccess(currentClass,
                                            memberClass,
                                            target,
                                            mods);
              try {
                  /*
                   * We're still here so class access was ok.
                   * Now try with default field access.
                   */
                  mods = mods & (~Modifier.PUBLIC);
                  Reflection.ensureMemberAccess(currentClass,
                                                memberClass,
                                                target,
                                                mods);
                  /*
                   * We're still here so access is ok without
                   * checking for protected.
                   */
                  return;
              } catch (IllegalAccessException e) {
                  /*
                   * Access failed but we're 'protected' so
                   * if the test below succeeds then we're ok.
                   */
                  if (isSubclassOf(currentClass, memberClass)) {
                      return;
                  } else {
                      throw e;
                  }
              }
          } else {
              Reflection.ensureMemberAccess(currentClass,
                                            memberClass,
                                            target,
                                            modifiers);
          }
      }
docs: /*
  Reflection.ensureMemberAccess is overly-restrictive
  due to a bug. We awkwardly work around it for now.