private Class loadFunctionClass()

in invoker/core/src/main/java/com/google/cloud/functions/invoker/runner/Invoker.java [357:377]


  private Class<?> loadFunctionClass() throws ClassNotFoundException {
    String target = functionTarget;
    ClassNotFoundException firstException = null;
    while (true) {
      try {
        return functionClassLoader.loadClass(target);
      } catch (ClassNotFoundException e) {
        if (firstException == null) {
          firstException = e;
        }
        // This might be a nested class like com.example.Foo.Bar. That will actually
        // appear as com.example.Foo$Bar as far as Class.forName is concerned. So we try to replace
        // every dot from the last to the first with a $ in the hope of finding a class we can load.
        int lastDot = target.lastIndexOf('.');
        if (lastDot < 0) {
          throw firstException;
        }
        target = target.substring(0, lastDot) + '$' + target.substring(lastDot + 1);
      }
    }
  }