{"record":{"id":"51ec3c7b219e416a","repo":"quarkusio/quarkus","slug":"location-already-set","errorCode":null,"errorMessage":"Location already set","messagePattern":"Location already set","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/deployment/src/main/java/io/quarkus/deployment/builditem/HotDeploymentWatchedFileBuildItem.java","lineNumber":112,"sourceCode":"    }\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\n        public HotDeploymentWatchedFileBuildItem build() {\n            return new HotDeploymentWatchedFileBuildItem(location, locationPredicate, restartNeeded);\n        }\n\n    }\n\n}\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/deployment/src/main/java/io/quarkus/deployment/builditem/HotDeploymentWatchedFileBuildItem.java#L94-L130","documentation":"Mirror of the reverse case: once the Builder's location string is set, calling setLocationPredicate would create an ambiguous watcher, so it throws IllegalArgumentException 'Location already set'. Exactly one of the two watch selectors may be configured.","triggerScenarios":"Invoking Builder.setLocationPredicate(...) after setLocation(...) on the same builder instance.","commonSituations":"Conditional code that sets a default location and then, on some branch, also tries to add a predicate; merging two configuration sources into one builder.","solutions":["Remove one of the two setter calls; keep the location if a single file is watched, otherwise keep only the predicate.","Use a new Builder when the watch target changes instead of overwriting the existing one.","Express a fixed location as a predicate if you need the predicate API consistently: p -> p.equals(location)."],"exampleFix":"// before\nHotDeploymentWatchedFileBuildItem item = HotDeploymentWatchedFileBuildItem.builder()\n        .setLocation(\"application.properties\")\n        .setLocationPredicate(p -> p.endsWith(\".yaml\"))\n        .build();\n// after\nHotDeploymentWatchedFileBuildItem item = HotDeploymentWatchedFileBuildItem.builder()\n        .setLocationPredicate(p -> p.equals(\"application.properties\") || p.endsWith(\".yaml\"))\n        .build();","handlingStrategy":"validation","validationCode":"HotDeploymentWatchedFileBuildItem.Builder b = HotDeploymentWatchedFileBuildItem.builder();\nif (location != null) {\n    b.setLocation(location);\n} else {\n    b.setLocationPredicate(predicate);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return builder.setLocationPredicate(p).build();\n} catch (IllegalArgumentException e) {\n    if (\"Location already set\".equals(e.getMessage())) {\n        return HotDeploymentWatchedFileBuildItem.builder().setLocationPredicate(p).build();\n    }\n    throw e;\n}","preventionTips":["Track builder state in a helper (location set vs predicate set) before adding a second selector","Merge multiple locations into one predicate: p -> p.equals(a) || p.equals(b)","Use one Builder per produced build item"],"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-12T22:17:10.623Z"}