{"record":{"id":"8c644d1c29971d75","repo":"quarkusio/quarkus","slug":"predicate-already-set","errorCode":null,"errorMessage":"Predicate already set","messagePattern":"Predicate already set","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/deployment/src/main/java/io/quarkus/deployment/builditem/HotDeploymentWatchedFileBuildItem.java","lineNumber":104,"sourceCode":"    }\n\n    /**\n     *\n     * @return {@code true} if a file change should result in an application restart, {@code false} otherwise\n     */\n    public boolean isRestartNeeded() {\n        return restartNeeded;\n    }\n\n    public static class Builder {\n\n        private String location;\n        private Predicate<String> locationPredicate;\n        private boolean restartNeeded = true;\n\n        public Builder setLocation(String location) {\n            if (locationPredicate != null) {\n                throw new IllegalArgumentException(\"Predicate already set\");\n            }\n            this.location = location;\n            return this;\n        }\n\n        public Builder setLocationPredicate(Predicate<String> locationPredicate) {\n            if (location != null) {\n                throw new IllegalArgumentException(\"Location already set\");\n            }\n            this.locationPredicate = locationPredicate;\n            return this;\n        }\n\n        public Builder setRestartNeeded(boolean restartNeeded) {\n            this.restartNeeded = restartNeeded;\n            return this;\n        }\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/deployment/src/main/java/io/quarkus/deployment/builditem/HotDeploymentWatchedFileBuildItem.java#L86-L122","documentation":"The HotDeploymentWatchedFileBuildItem.Builder allows exactly one of location or predicate. Once a predicate has been set, calling setLocation would silently create an ambiguous watcher, so the builder throws IllegalArgumentException 'Predicate already set'.","triggerScenarios":"Chaining builder calls where setLocationPredicate(...) is invoked before setLocation(...), or calling both setters on the same Builder instance.","commonSituations":"Code paths that merge defaults (predicate) with user config (location) on the same builder; copy-pasted builder chains where the wrong setter was left in.","solutions":["Choose one mechanism: if you need string matching, use setLocation and drop setLocationPredicate (and vice versa).","Use a fresh Builder instance per watch entry instead of reusing/reconfiguring one.","If you must support both, convert the location check into a predicate: p -> p.equals(location) and set only the predicate."],"exampleFix":"// before\nHotDeploymentWatchedFileBuildItem item = HotDeploymentWatchedFileBuildItem.builder()\n        .setLocationPredicate(p -> p.startsWith(\"config/\"))\n        .setLocation(\"config/app.yaml\")\n        .build();\n// after\nHotDeploymentWatchedFileBuildItem item = HotDeploymentWatchedFileBuildItem.builder()\n        .setLocationPredicate(p -> p.startsWith(\"config/\"))\n        .build();","handlingStrategy":"validation","validationCode":"HotDeploymentWatchedFileBuildItem.Builder b = HotDeploymentWatchedFileBuildItem.builder();\nif (location != null) {\n    b.setLocation(location);\n} else if (predicate != null) {\n    b.setLocationPredicate(predicate);\n} else {\n    return; // nothing to watch\n}","typeGuard":null,"tryCatchPattern":"try {\n    return builder.setLocation(location).build();\n} catch (IllegalArgumentException e) {\n    if (\"Predicate already set\".equals(e.getMessage())) {\n        return HotDeploymentWatchedFileBuildItem.builder().setLocation(location).build();\n    }\n    throw e;\n}","preventionTips":["Decide the selector style (string vs predicate) once per watch entry","Create a fresh Builder for each item; never reconfigure a partially built one","Wrap builder construction in a helper that accepts exactly one selector"],"tags":["quarkus","live-reload","builder","illegal-argument"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}