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

  1. Remove one of the two setter calls; keep the location if a single file is watched, otherwise keep only the predicate.
  2. Use a new Builder when the watch target changes instead of overwriting the existing one.
  3. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/51ec3c7b219e416a. Report an issue: GitHub.