api/src/main/java/com/google/apphosting/utils/servlet/ee10/DeferredTaskServlet.java [163:236]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  protected Runnable readRequest(HttpServletRequest req, HttpServletResponse resp)
      throws DeferredTaskException {
    String contentType = req.getHeader("content-type");
    if (contentType == null
        || !contentType.equals(DeferredTaskContext.RUNNABLE_TASK_CONTENT_TYPE)) {
      throw new DeferredTaskException(
          new IllegalArgumentException(
              "Invalid content-type header."
                  + " received: '"
                  + (String.valueOf(contentType))
                  + "' expected: '"
                  + DeferredTaskContext.RUNNABLE_TASK_CONTENT_TYPE
                  + "'"));
    }

    try {
      ServletInputStream stream = req.getInputStream();
      ObjectInputStream objectStream =
          new ObjectInputStream(stream) {
            @Override
            protected Class<?> resolveClass(ObjectStreamClass desc)
                throws IOException, ClassNotFoundException {
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              String name = desc.getName();
              try {
                return Class.forName(name, false, classLoader);
              } catch (ClassNotFoundException ex) {
                // This one should also handle primitive types
                return super.resolveClass(desc);
              }
            }

            @Override
            protected Class<?> resolveProxyClass(String[] interfaces)
                throws IOException, ClassNotFoundException {
              // Note This logic was copied from ObjectInputStream.java in the
              // JDK, and then modified to use the thread context class loader instead of the
              // "latest" loader that is used there.
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              ClassLoader nonPublicLoader = null;
              boolean hasNonPublicInterface = false;

              // define proxy in class loader of non-public interface(s), if any
              Class<?>[] classObjs = new Class<?>[interfaces.length];
              for (int i = 0; i < interfaces.length; i++) {
                Class<?> cl = Class.forName(interfaces[i], false, classLoader);
                if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
                  if (hasNonPublicInterface) {
                    if (nonPublicLoader != cl.getClassLoader()) {
                      throw new IllegalAccessError(
                          "conflicting non-public interface class loaders");
                    }
                  } else {
                    nonPublicLoader = cl.getClassLoader();
                    hasNonPublicInterface = true;
                  }
                }
                classObjs[i] = cl;
              }
              try {
                return Proxy.getProxyClass(
                    hasNonPublicInterface ? nonPublicLoader : classLoader, classObjs);
              } catch (IllegalArgumentException e) {
                throw new ClassNotFoundException(null, e);
              }
            }
          };
     // Replacing DeferredTask to Runnable as we have DeferredTask in the 2 classloaders
     // (runtime and application), but we cannot cast one with another one.
     return (Runnable) objectStream.readObject();
    } catch (ClassNotFoundException | IOException | ClassCastException e) {
      throw new DeferredTaskException(e);
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



api/src/main/java/com/google/apphosting/utils/servlet/DeferredTaskServlet.java [163:236]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  protected Runnable readRequest(HttpServletRequest req, HttpServletResponse resp)
      throws DeferredTaskException {
    String contentType = req.getHeader("content-type");
    if (contentType == null
        || !contentType.equals(DeferredTaskContext.RUNNABLE_TASK_CONTENT_TYPE)) {
      throw new DeferredTaskException(
          new IllegalArgumentException(
              "Invalid content-type header."
                  + " received: '"
                  + (String.valueOf(contentType))
                  + "' expected: '"
                  + DeferredTaskContext.RUNNABLE_TASK_CONTENT_TYPE
                  + "'"));
    }

    try {
      ServletInputStream stream = req.getInputStream();
      ObjectInputStream objectStream =
          new ObjectInputStream(stream) {
            @Override
            protected Class<?> resolveClass(ObjectStreamClass desc)
                throws IOException, ClassNotFoundException {
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              String name = desc.getName();
              try {
                return Class.forName(name, false, classLoader);
              } catch (ClassNotFoundException ex) {
                // This one should also handle primitive types
                return super.resolveClass(desc);
              }
            }

            @Override
            protected Class<?> resolveProxyClass(String[] interfaces)
                throws IOException, ClassNotFoundException {
              // Note This logic was copied from ObjectInputStream.java in the
              // JDK, and then modified to use the thread context class loader instead of the
              // "latest" loader that is used there.
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              ClassLoader nonPublicLoader = null;
              boolean hasNonPublicInterface = false;

              // define proxy in class loader of non-public interface(s), if any
              Class<?>[] classObjs = new Class<?>[interfaces.length];
              for (int i = 0; i < interfaces.length; i++) {
                Class<?> cl = Class.forName(interfaces[i], false, classLoader);
                if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
                  if (hasNonPublicInterface) {
                    if (nonPublicLoader != cl.getClassLoader()) {
                      throw new IllegalAccessError(
                          "conflicting non-public interface class loaders");
                    }
                  } else {
                    nonPublicLoader = cl.getClassLoader();
                    hasNonPublicInterface = true;
                  }
                }
                classObjs[i] = cl;
              }
              try {
                return Proxy.getProxyClass(
                    hasNonPublicInterface ? nonPublicLoader : classLoader, classObjs);
              } catch (IllegalArgumentException e) {
                throw new ClassNotFoundException(null, e);
              }
            }
          };
     // Replacing DeferredTask to Runnable as we have DeferredTask in the 2 classloaders
     // (runtime and application), but we cannot cast one with another one.
     return (Runnable) objectStream.readObject();
    } catch (ClassNotFoundException | IOException | ClassCastException e) {
      throw new DeferredTaskException(e);
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



