{"record":{"id":"deb1ebf5c252824c","repo":"perwendel/spark","slug":"static-file-location-has-already-been-set","errorCode":null,"errorMessage":"Static file location has already been set","messagePattern":"Static file location has already been set","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/java/spark/Service.java","lineNumber":346,"sourceCode":"        return this;\n    }\n\n    /**\n     * Sets the folder in classpath serving static files. Observe: this method\n     * must be called before all other methods.\n     *\n     * @param folder the folder in classpath.\n     * @return the object with folder set\n     */\n    public synchronized Service staticFileLocation(String folder) {\n        if (initialized && !isRunningFromServlet()) {\n            throwBeforeRouteMappingException();\n        }\n\n        if (!staticFilesConfiguration.isStaticResourcesSet()) {\n            staticFilesConfiguration.configure(folder);\n        } else {\n            LOG.warn(\"Static file location has already been set\");\n        }\n        return this;\n    }\n\n    /**\n     * Sets the external folder serving static files. <b>Observe: this method\n     * must be called before all other methods.</b>\n     *\n     * @param externalFolder the external folder serving static files.\n     * @return the object with external folder set\n     */\n    public synchronized Service externalStaticFileLocation(String externalFolder) {\n        if (initialized && !isRunningFromServlet()) {\n            throwBeforeRouteMappingException();\n        }\n\n        if (!staticFilesConfiguration.isExternalStaticResourcesSet()) {\n            staticFilesConfiguration.configureExternal(externalFolder);","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/perwendel/spark/blob/1973e402f5d4c1442ad34a1d38ed0758079f7773/src/main/java/spark/Service.java#L328-L364","documentation":"Service.staticFileLocation logs 'Static file location has already been set' instead of applying the new folder: classpath static resources can only be configured once per service. The second call is silently ignored (warning only), so the developer's intended folder never takes effect.","triggerScenarios":"Calling staticFileLocation(...) a second time after a previous call already configured static resources; calling both staticFileLocation and externalStaticFileLocation in ways that collide on configuration state; framework hot-reload re-invoking the init code.","commonSituations":"Copy-pasted init code in multiple config classes/registries; switching from one resource folder to another without realizing the first call wins; running init twice due to servlet container restart semantics.","solutions":["Call staticFileLocation exactly once, before route mapping, with the single desired folder.","Remove the duplicate staticFileLocation call found via the LOG.warn output.","If multiple folders are needed, serve them via separate routes or an external location instead.","Restructure initialization so service setup runs once (guard with an initialized flag)."],"exampleFix":"// before\nservice.staticFileLocation(\"/public\");\nservice.staticFileLocation(\"/assets\"); // ignored, warns\n// after\nservice.staticFileLocation(\"/public\"); // single authoritative root only","handlingStrategy":"validation","validationCode":"if (!serviceInitialized) {\n    service.staticFileLocation(\"/public\");\n    serviceInitialized = true;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call staticFileLocation once, before route mapping, in a single init path.","Guard initialization with a boolean or Singleton to avoid duplicate configuration.","Search the codebase for all staticFileLocation calls during review.","Check logs for 'already been set' warnings at startup."],"tags":["configuration","static-files","duplicate-config"],"backgroundTag":"conflicting-config-options","analyzedSha":"1973e402f5d4c1442ad34a1d38ed0758079f7773","analyzedAt":"2026-09-10T14:38:22.866Z","contentChangedAt":"2026-09-10T14:38:22.866Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}