apereo/cas · warning

No resource defined to prepare.

Error message

No resource defined to prepare.

What it means

This is a logged warning (not an exception) emitted by ResourceUtils.exportClasspathResourceToFile when the Resource argument passed in is null. The method logs it and returns null instead of exporting anything, so callers silently get no exported file.

Solutions

  1. Check that the classpath resource actually exists before calling exportClasspathResourceToFile (e.g. ClassPathResource.exists()).
  2. Fix the resource location string / dependency so resource resolution returns a non-null Resource.
  3. Guard the call site against a null resource and skip export with your own log message.
  4. If null is expected, tolerate it: the method returns null by design (it is @Nullable).

Example fix

// before
ResourceUtils.exportClasspathResourceToFile(dir, resource);
// after
if (resource != null && resource.exists()) {
    ResourceUtils.exportClasspathResourceToFile(dir, resource);
} else {
    LOGGER.debug("Skipping export: no classpath resource to prepare");
}
Defensive patterns

Strategy: validation

Validate before calling

if (resource == null || !resource.exists()) {
    LOGGER.warn("Skipping export: classpath resource undefined");
    return;
}

Type guard

boolean isUsableResource(Resource r) { return r != null && r.getFilename() != null; }

Prevention

When it happens

Trigger: Calling exportClasspathResourceToFile(parentDirectory, resource) with a null resource — typically when upstream code resolves a classpath resource (e.g. via ResourceLoader or a pattern like classpath:/template/**) and no matching resource exists, producing a null instead of a resource.

Common situations: Exporting CAS templates/configuration from the classpath at startup where the resource was removed, renamed, or is behind an optional module that is not on the classpath; a misconfigured resource location string yields null and is passed straight through.

Related errors


AI-assisted analysis of apereo/cas@e7288fc434 (2026-09-08). Data as JSON: /api/errors/268118fc2f84c998. Report an issue: GitHub.

Appendix: source

Thrown at core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/ResourceUtils.java:186

    public static AbstractResource getResourceFrom(final String location) throws IOException {
        val resource = getRawResourceFrom(location);
        if (!resource.exists() || (resource.isFile() && resource.getFile().isFile() && !resource.isReadable())) {
            throw new FileNotFoundException("Resource " + location + " does not exist or is unreadable");
        }
        return resource;
    }

    /**
     * Export classpath resource to file.
     *
     * @param parentDirectory the parent directory
     * @param resource        the resource
     * @return the resource
     */
    public static @Nullable Resource exportClasspathResourceToFile(final File parentDirectory, final Resource resource) {
        LOGGER.trace("Preparing classpath resource [{}]", resource);
        if (resource == null) {
            LOGGER.warn("No resource defined to prepare.");
            return null;
        }
        if (!parentDirectory.exists() && !parentDirectory.mkdirs()) {
            LOGGER.warn("Unable to create folder [{}]", parentDirectory);
        }
        val destination = new File(parentDirectory, Objects.requireNonNull(resource.getFilename()));
        FunctionUtils.doUnchecked(_ -> {
            if (destination.exists()) {
                LOGGER.trace("Deleting resource directory [{}]", destination);
                FileUtils.deleteQuietly(destination);
            }
            try (val out = new FileOutputStream(destination);
                 val input = resource.getInputStream()) {
                input.transferTo(out);
            }
        });
        return new FileSystemResource(destination);
    }

View on GitHub (pinned to e7288fc434)