{"record":{"id":"9159d578df5a8cd0","repo":"apereo/cas","slug":"metadata-artifact-at-is-empty-and-invalid-and","errorCode":null,"errorMessage":"Metadata artifact at [{}] is empty and invalid and will be deleted","messagePattern":"Metadata artifact at \\[(.+?)\\] is empty and invalid and will be deleted","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"support/cas-server-support-saml-idp-core/src/main/java/org/apereo/cas/support/saml/idp/metadata/locator/FileSystemSamlIdPMetadataLocator.java","lineNumber":129,"sourceCode":"                : new File(this.metadataLocation, getAppliesToFor(registeredService));\n            LOGGER.debug(\"Metadata directory location for [{}] is [{}]\", samlRegisteredService.getName(), serviceDirectory);\n            if (serviceDirectory.exists()) {\n                val artifact = new File(serviceDirectory, artifactName);\n                LOGGER.trace(\"Artifact location for [{}] and [{}] is [{}]\", artifactName, samlRegisteredService.getName(), artifact);\n                if (artifact.exists()) {\n                    LOGGER.debug(\"Using metadata artifact [{}] at [{}]\", artifactName, artifact);\n                    return ResourceUtils.toFileSystemResource(artifact);\n                }\n            }\n        }\n        initializeMetadataDirectory();\n        val resource = ResourceUtils.toFileSystemResource(new File(this.metadataLocation, artifactName));\n        if (resource.exists() && resource.isReadable()) {\n            val content = FileUtils.readFileToString(resource.getFile(), StandardCharsets.UTF_8);\n            if (StringUtils.isNotBlank(content)) {\n                return resolveContentToResource(content);\n            }\n            LOGGER.warn(\"Metadata artifact at [{}] is empty and invalid and will be deleted\", resource);\n            FileUtils.deleteQuietly(resource.getFile());\n        }\n        return ResourceUtils.toFileSystemResource(resource.getFile());\n    }\n\n    protected void initializeMetadataDirectory() {\n        if (!this.metadataLocation.exists()) {\n            LOGGER.debug(\"Metadata directory [{}] does not exist. Creating...\", this.metadataLocation);\n            if (!this.metadataLocation.mkdir()) {\n                throw new IllegalArgumentException(\"Metadata directory location \" + this.metadataLocation + \" cannot be located/created\");\n            }\n        }\n    }\n}\n","sourceCodeStart":111,"sourceCodeEnd":144,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-saml-idp-core/src/main/java/org/apereo/cas/support/saml/idp/metadata/locator/FileSystemSamlIdPMetadataLocator.java#L111-L144","documentation":"FileSystemSamlIdPMetadataLocator.getMetadataArtifact() reads the IdP metadata artifact file under the configured metadata location. If the file exists and is readable but its content is blank, it logs this warning, deletes the empty file, and returns the (now removed) file resource, forcing later resolution to regenerate or fail. It indicates corrupted/empty metadata storage.","triggerScenarios":"Calling resolveMetadata/resolveSigningKey/resolveEncryptionKey (or the locator directly) when the artifact file at {metadataLocation}/{artifactName} exists but contains zero bytes or only whitespace, e.g. after a crashed write or a truncating touch.","commonSituations":"Disk-full or crash during metadata generation leaving a 0-byte file; an admin running 'touch' on the metadata file; mounting an empty file in the metadata directory via Docker; storage cleanup jobs truncating files.","solutions":["Delete the empty artifact file and let CAS regenerate the metadata (the locator deletes it automatically; restart the flow)","Restore the metadata file from backup or re-run metadata generation/upload","Check disk space and I/O health to find why the write was truncated","Verify the metadataLocation path and mounted volume point at the directory CAS actually wrote"],"exampleFix":"// before: manually recreating empty file\ntouch /etc/cas/saml/idp-metadata.json\n// after: remove and regenerate\nrm /etc/cas/saml/idp-metadata.json\n# restart metadata generation flow in CAS","handlingStrategy":"fallback","validationCode":"// precheck artifact content before resolution\nval content = Files.readString(Path.of(metadataLocation, artifactName));\nif (content.isBlank()) regenerateMetadata();","typeGuard":"function artifactValid(r) { return r != null && r.exists() && r.isReadable() && !readAll(r).isBlank(); }","tryCatchPattern":"try { resource = locator.getMetadataArtifact(service); }\ncatch (Exception e) { resource = regenerateOrDefault(service); }","preventionTips":["Monitor metadata directory for 0-byte files","Avoid touch/truncation of artifact files; restore from backup instead","Ensure adequate disk space for metadata writes"],"tags":["saml","idp","metadata","empty-file","filesystem"],"backgroundTag":"empty-required-field","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"}