apereo/cas · warning

Unable to create folder

Error message

Unable to create folder [{}]

What it means

A logged warning in ResourceUtils.exportClasspathResourceToFile issued when the target parent directory does not exist and File.mkdirs() fails to create it. Execution continues anyway, so the subsequent file write into that directory will likely fail downstream.

Solutions

  1. Ensure the parent directory exists and is writable by the CAS process user before startup (mkdir -p and chown).
  2. Check filesystem mount flags — remount read-only volumes read-write or pick another destination.
  3. Verify no regular file exists at the directory path; remove or rename it.
  4. Run the container/JVM with sufficient filesystem permissions (e.g. non-root user with correct volume ownership).

Example fix

// before
File dir = new File("/etc/cas/templates"); // may not be writable
ResourceUtils.exportClasspathResourceToFile(dir, resource);
// after
File dir = new File("/etc/cas/templates");
if (!dir.exists() && !dir.mkdirs()) {
    throw new IllegalStateException("Cannot create directory " + dir);
}
ResourceUtils.exportClasspathResourceToFile(dir, resource);
Defensive patterns

Strategy: validation

Validate before calling

File dir = parentDirectory;
if (!dir.exists()) {
    if (!dir.mkdirs()) {
        throw new IllegalStateException("Cannot create directory " + dir + "; check permissions/mounts");
    }
}
if (!dir.canWrite()) {
    throw new IllegalStateException("Directory not writable: " + dir);
}

Prevention

When it happens

Trigger: Calling exportClasspathResourceToFile(parentDirectory, resource) where parentDirectory does not exist and cannot be created — e.g. the path points inside a read-only filesystem, a file already exists at that path, or permission to create directories is missing.

Common situations: CAS configured to export resources into /etc/cas/... or a container volume that is mounted read-only; running as a non-root user without write permission on the parent path; a stale file occupying the intended directory path.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


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

Appendix: source

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

        }
        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);
    }


    /**
     * Prepare classpath resource if needed file.

View on GitHub (pinned to e7288fc434)