quarkusio/quarkus · error · IllegalArgumentException
Location already set
Error message
Location already set
What it means
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.
Source
Thrown at core/deployment/src/main/java/io/quarkus/deployment/builditem/HotDeploymentWatchedFileBuildItem.java:112
}
public static class Builder {
private String location;
private Predicate<String> locationPredicate;
private boolean restartNeeded = true;
public Builder setLocation(String location) {
if (locationPredicate != null) {
throw new IllegalArgumentException("Predicate already set");
}
this.location = location;
return this;
}
public Builder setLocationPredicate(Predicate<String> locationPredicate) {
if (location != null) {
throw new IllegalArgumentException("Location already set");
}
this.locationPredicate = locationPredicate;
return this;
}
public Builder setRestartNeeded(boolean restartNeeded) {
this.restartNeeded = restartNeeded;
return this;
}
public HotDeploymentWatchedFileBuildItem build() {
return new HotDeploymentWatchedFileBuildItem(location, locationPredicate, restartNeeded);
}
}
}
View on GitHub (pinned to e1c734241f)
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).
Example fix
// before
HotDeploymentWatchedFileBuildItem item = HotDeploymentWatchedFileBuildItem.builder()
.setLocation("application.properties")
.setLocationPredicate(p -> p.endsWith(".yaml"))
.build();
// after
HotDeploymentWatchedFileBuildItem item = HotDeploymentWatchedFileBuildItem.builder()
.setLocationPredicate(p -> p.equals("application.properties") || p.endsWith(".yaml"))
.build(); Defensive patterns
Strategy: validation
Validate before calling
HotDeploymentWatchedFileBuildItem.Builder b = HotDeploymentWatchedFileBuildItem.builder();
if (location != null) {
b.setLocation(location);
} else {
b.setLocationPredicate(predicate);
} Try / catch
try {
return builder.setLocationPredicate(p).build();
} catch (IllegalArgumentException e) {
if ("Location already set".equals(e.getMessage())) {
return HotDeploymentWatchedFileBuildItem.builder().setLocationPredicate(p).build();
}
throw e;
} Prevention
- 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
When it happens
Trigger: Invoking Builder.setLocationPredicate(...) after setLocation(...) on the same builder instance.
Common situations: 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.
Related errors
- Predicate already set
- One of either visitorFunction or inputTransformer must be se
- name cannot be null
- Name cannot start with '/':${name}
- Either location or predicate must be set
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/51ec3c7b219e416a.
Report an issue: GitHub.