{"record":{"id":"ce17189d05c11e1e","repo":"quarkusio/quarkus","slug":"can-not-write-configuration-as-it-was-read-from-an","errorCode":null,"errorMessage":"Can not write configuration as it was read from an alternate source: ${source}","messagePattern":"Can not write configuration as it was read from an alternate source: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigImpl.java","lineNumber":223,"sourceCode":"    public int hashCode() {\n        return Objects.hash(debug, registries);\n    }\n\n    @Override\n    public String toString() {\n        return this.getClass().getSimpleName() +\n                \"{debug=\" + debug +\n                \", registries=\" + registries +\n                \", configSource=\" + configSource +\n                '}';\n    }\n\n    static void persistConfigSource(RegistriesConfigImpl config) throws IOException {\n        Path targetFile = config.configSource.getFilePath();\n        if (config.configSource == ConfigSource.DEFAULT) {\n            targetFile = RegistriesConfigLocator.getDefaultConfigYamlLocation();\n        } else if (targetFile == null) {\n            throw new UnsupportedOperationException(\n                    String.format(\"Can not write configuration as it was read from an alternate source: %s\",\n                            config.configSource.describe()));\n        }\n        config.persist(targetFile);\n    }\n\n    static class Serializer extends ValueSerializer<RegistriesConfigImpl> {\n        @Override\n        public void serialize(RegistriesConfigImpl value, JsonGenerator gen, SerializationContext ctxt) {\n            boolean isDefaultDebug = !value.debug;\n            boolean isDefaultList = RegistryConfigImpl.isDefaultList(value.registries);\n\n            if (isDefaultDebug && isDefaultList) {\n                gen.writeNumber(\"\");\n            } else {\n                gen.writeStartObject();\n                if (gen instanceof YAMLGenerator) {\n                    if (!isDefaultDebug) {","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigImpl.java#L205-L241","documentation":"persistConfigSource refuses to write the registries configuration when it was loaded from a source that has no backing file path (e.g. an in-memory stream, reader, or synthesized default config source). Writing back would silently overwrite nothing or the wrong file, so it fails fast with UnsupportedOperationException.","triggerScenarios":"Calling persistConfigSource (via persist) on a RegistriesConfigImpl whose ConfigSource is an alternate (getFilePath() == null and not ConfigSource.DEFAULT) — typically after load(InputStream)/load(Reader).","commonSituations":"Tools that load registry config from a custom stream and then try to save user changes (e.g. `quarkus registry add-config` style flows) without knowing where to write.","solutions":["Load the config from a file-based source (ConfigSource.FileConfigSource) or the default config location before persisting","Call persist(Path) explicitly with the target file instead of relying on the original source","If using load(InputStream/Reader), track the originating file yourself and persist to that path"],"exampleFix":"// before\nRegistriesConfig cfg = RegistriesConfigLocator.load(stream);\nRegistriesConfigImpl.persistConfigSource((RegistriesConfigImpl) cfg); // throws\n// after\nRegistriesConfigImpl.persistConfigSource(\n    (RegistriesConfigImpl) RegistriesConfigLocator.loadDefault()); // or persist(Path)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean isPersistable(RegistriesConfigImpl cfg) {\n    return cfg.configSource == ConfigSource.DEFAULT || cfg.configSource.getFilePath() != null;\n}","tryCatchPattern":"try { RegistriesConfigImpl.persistConfigSource(cfg); } catch (UnsupportedOperationException e) { if (e.getMessage().startsWith(\"Can not write configuration\")) { persistToExplicitPath(cfg, userConfigPath); } else throw e; }","preventionTips":["Only persist configs loaded from file/default sources","For stream-loaded configs, call persist(Path) with a known target","Track the origin of configs loaded via load(InputStream/Reader)"],"tags":["configuration","persistence","io"],"backgroundTag":"read-only-config-source","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}