{"record":{"id":"d89101a03177bd82","repo":"apereo/cas","slug":"input-stream-from-resource-appears-empty-mov","errorCode":null,"errorMessage":"Input stream from resource [{}] appears empty. Moving on...","messagePattern":"Input stream from resource \\[(.+?)\\] appears empty\\. Moving on\\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"support/cas-server-support-saml-mdui-core/src/main/java/org/apereo/cas/support/saml/mdui/AbstractMetadataResolverAdapter.java","lineNumber":117,"sourceCode":"\n    protected InputStream getResourceInputStream(final Resource resource, final String entityId) throws IOException {\n        LOGGER.debug(\"Locating metadata resource from input stream.\");\n        if (!resource.exists() || !resource.isReadable()) {\n            throw new FileNotFoundException(\"Resource does not exist or is unreadable\");\n        }\n        return resource.getInputStream();\n    }\n\n    private List<MetadataResolver> loadMetadataFromResource(final MetadataFilter metadataFilter, final Resource resource,\n                                                            final String entityId) {\n        LOGGER.debug(\"Evaluating metadata resource [{}]\", resource.getFilename());\n        try (val in = getResourceInputStream(resource, entityId)) {\n            if (in.available() > 0) {\n                LOGGER.debug(\"Parsing [{}]\", resource.getFilename());\n                val document = this.configBean.getParserPool().parse(in);\n                return buildSingleMetadataResolver(metadataFilter, resource, document);\n            }\n            LOGGER.warn(\"Input stream from resource [{}] appears empty. Moving on...\", resource.getFilename());\n        } catch (final Exception e) {\n            LoggingUtils.warn(LOGGER, \"Could not retrieve input stream from resource. Moving on...\", e);\n        }\n        return new ArrayList<>();\n    }\n\n    /**\n     * Build single metadata resolver.\n     *\n     * @param metadataFilterChain the metadata filters chained together\n     * @param resource            the resource\n     * @param document            the xml document to parse\n     * @return list of resolved metadata from resources.\n     */\n    private List<MetadataResolver> buildSingleMetadataResolver(final MetadataFilter metadataFilterChain, final Resource resource,\n                                                               final Document document) {\n        val metadataRoot = document.getDocumentElement();\n        val metadataProvider = new DOMMetadataResolver(metadataRoot);","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-saml-mdui-core/src/main/java/org/apereo/cas/support/saml/mdui/AbstractMetadataResolverAdapter.java#L99-L135","documentation":"While building the MDUI metadata aggregate, the input stream for a metadata resource reported zero available bytes. CAS logs this warning and skips the resource, returning an empty list for that resolver contribution.","triggerScenarios":"loadMetadataFromResource opens the resource's stream and in.available() == 0 — an empty metadata file, a truncated download, or a stream that has no buffered bytes yet (some remote resources legitimately report 0 available without being empty).","commonSituations":"Empty or partially written metadata XML on disk; HTTP resource returning empty body; network resource whose available() semantics mislead; race while metadata file is regenerated.","solutions":["Verify the metadata resource file exists and is non-empty (ls -l / curl -I).","Re-download or re-sync the metadata source.","If the resource is remote and streams lazily, prefer a cached/downloaded local copy instead of relying on available().","Check the preceding exception-free path: no other error means genuinely empty content."],"exampleFix":"// before: pointing at empty file\nmetadata-reference: file:/etc/cas/mdui/empty.xml\n// after\nmetadata-reference: file:/etc/cas/mdui/valid-metadata.xml","handlingStrategy":"validation","validationCode":"var res = applicationContext.getResource(path);\nif (!res.exists() || res.contentLength() == 0) {\n    LOGGER.warn(\"Metadata resource empty: {}\", path);\n    return List.of();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate metadata files are non-empty and well-formed after every sync/download.","Avoid racing with metadata regeneration jobs.","Prefer local cached copies for remote metadata consumed by MDUI."],"tags":["metadata","file","empty-input"],"backgroundTag":"empty-response-body","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"}