code: public static boolean isValid(Resource resource) {
          return resource instanceof ResourceHandle
                  ? ((ResourceHandle) resource).isValid()
                  : resource != null && resource.getResourceResolver().getResource(resource.getPath()) != null;
      }
docs: the universal validation test