{"record":{"id":"268118fc2f84c998","repo":"apereo/cas","slug":"no-resource-defined-to-prepare","errorCode":null,"errorMessage":"No resource defined to prepare.","messagePattern":"No resource defined to prepare\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/ResourceUtils.java","lineNumber":186,"sourceCode":"    public static AbstractResource getResourceFrom(final String location) throws IOException {\n        val resource = getRawResourceFrom(location);\n        if (!resource.exists() || (resource.isFile() && resource.getFile().isFile() && !resource.isReadable())) {\n            throw new FileNotFoundException(\"Resource \" + location + \" does not exist or is unreadable\");\n        }\n        return resource;\n    }\n\n    /**\n     * Export classpath resource to file.\n     *\n     * @param parentDirectory the parent directory\n     * @param resource        the resource\n     * @return the resource\n     */\n    public static @Nullable Resource exportClasspathResourceToFile(final File parentDirectory, final Resource resource) {\n        LOGGER.trace(\"Preparing classpath resource [{}]\", resource);\n        if (resource == null) {\n            LOGGER.warn(\"No resource defined to prepare.\");\n            return null;\n        }\n        if (!parentDirectory.exists() && !parentDirectory.mkdirs()) {\n            LOGGER.warn(\"Unable to create folder [{}]\", parentDirectory);\n        }\n        val destination = new File(parentDirectory, Objects.requireNonNull(resource.getFilename()));\n        FunctionUtils.doUnchecked(_ -> {\n            if (destination.exists()) {\n                LOGGER.trace(\"Deleting resource directory [{}]\", destination);\n                FileUtils.deleteQuietly(destination);\n            }\n            try (val out = new FileOutputStream(destination);\n                 val input = resource.getInputStream()) {\n                input.transferTo(out);\n            }\n        });\n        return new FileSystemResource(destination);\n    }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/ResourceUtils.java#L168-L204","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check that the classpath resource actually exists before calling exportClasspathResourceToFile (e.g. ClassPathResource.exists()).","Fix the resource location string / dependency so resource resolution returns a non-null Resource.","Guard the call site against a null resource and skip export with your own log message.","If null is expected, tolerate it: the method returns null by design (it is @Nullable)."],"exampleFix":"// before\nResourceUtils.exportClasspathResourceToFile(dir, resource);\n// after\nif (resource != null && resource.exists()) {\n    ResourceUtils.exportClasspathResourceToFile(dir, resource);\n} else {\n    LOGGER.debug(\"Skipping export: no classpath resource to prepare\");\n}","handlingStrategy":"validation","validationCode":"if (resource == null || !resource.exists()) {\n    LOGGER.warn(\"Skipping export: classpath resource undefined\");\n    return;\n}","typeGuard":"boolean isUsableResource(Resource r) { return r != null && r.getFilename() != null; }","tryCatchPattern":null,"preventionTips":["Always check Resource.exists() after resolution before exporting.","Fail fast at startup if a mandatory classpath resource cannot be resolved.","Log the configured resource location string to catch typos early."],"tags":["null-argument","resource","logging"],"backgroundTag":"null-argument","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}