code: private static <T, E extends Exception> T runWithOurClassLoader(final Callable<T> action, Class<E> allowed) throws E {
          PrivilegedExceptionAction<T> actionWithClassloader = new PrivilegedExceptionAction<T>() {
              public T run() throws Exception {
                  ClassLoader original = Thread.currentThread().getContextClassLoader();
                  ClassLoader ours = XmlUtil.class.getClassLoader();
                  // Don't override the TCCL if it is not needed.
                  if (original == ours) {
                      return action.call();
                  } else {
                      try {
                          Thread.currentThread().setContextClassLoader(ours);
                          return action.call();
                      } finally {
                          Thread.currentThread().setContextClassLoader(original);
                      }
                  }
              }
          };
          try {
              return AccessController.doPrivileged(actionWithClassloader);
          } catch (PrivilegedActionException e) {
              Throwable cause = e.getCause();
              if (allowed.isInstance(cause)) {
                  throw allowed.cast(cause);
              } else {
                  throw (Error) new AssertionError().initCause(cause);
              }
          }
      }
docs: Performs an action using this Class's ClassLoader as the Thread context ClassLoader.
  
  @param action the action to perform
  @param allowed an Exception that might be thrown by the action
  @param <T> the type of the result
  @param <E> the type of the allowed Exception
  @return the result of the action
  @throws E if the action threw the allowed Exception