apereo/cas · warning

LoggingUtils.warn(LOGGER, e)

Error message

LoggingUtils.warn(LOGGER, e)

What it means

ResourceUtils.doesResourceExist(String) probes whether a resource location exists via a ResourceLoader. Any exception during the probe (malformed URL, unsupported prefix, I/O error) is swallowed and logged at WARN via LoggingUtils.warn, and the method returns false. A warn here therefore means 'existence could not be determined', which is treated as 'does not exist'.

Solutions

  1. Read the warn's derived exception message to see why the resource lookup failed (usually a malformed URL or bad prefix)
  2. Correct the resource location string (verify prefix: classpath:, file:, http:, etc.)
  3. Verify the resource actually exists at the given path and is readable by the CAS process user
  4. Remember a false return may mean 'unknown' rather than 'missing' — do not build critical logic on this probe alone

Example fix

// before
boolean ok = ResourceUtils.doesResourceExist("/etc/cas/config/services.json"); // no scheme -> probe throws
// after
boolean ok = ResourceUtils.doesResourceExist("file:/etc/cas/config/services.json");
Defensive patterns

Strategy: fallback

Validate before calling

if (location == null || location.isBlank() || !location.matches("^(classpath|file|https?)://.*")) {
    log.warn("Suspicious resource location: {}", location);
}

Try / catch

try {
    boolean exists = ResourceUtils.doesResourceExist(location);
} catch (Exception e) {
    LoggingUtils.warn(LOGGER, e);
    exists = false; // probe already returns false on exception
}

Prevention

When it happens

Trigger: Calling ResourceUtils.doesResourceExist(location) where resourceLoader.getResource(location) throws — e.g. malformed resource URLs, invalid classpath:/file:/http: prefixes, or unreachable network resources.

Common situations: Typo'd resource paths in configuration; checking resources on mounted/network volumes that are unavailable; placeholder resolution producing an invalid resource string; Spring resource-prefix misuse.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

        val lowerCase = resource.toLowerCase(Locale.ENGLISH);
        return lowerCase.startsWith(RESOURCE_URL_PREFIX);
    }

    /**
     * Determines whether the resource exists.
     *
     * @param resource       the resource
     * @param resourceLoader the resource loader
     * @return true/false
     */
    public static boolean doesResourceExist(final String resource, final ResourceLoader resourceLoader) {
        try {
            if (StringUtils.isNotBlank(resource)) {
                val res = resourceLoader.getResource(resource);
                return doesResourceExist(res);
            }
        } catch (final Exception e) {
            LoggingUtils.warn(LOGGER, e);
        }
        return false;
    }

    /**
     * Determines whether the resource exists.
     * <p>
     * On Windows, reading one byte from a directory does not return length greater than zero so an explicit directory
     * check is needed.
     *
     * @param res the res
     * @return true/false
     */
    public static boolean doesResourceExist(final Resource res) {
        if (res == null) {
            return false;
        }
        try {

View on GitHub (pinned to e7288fc434)