quarkusio/quarkus · error · IllegalArgumentException

Either location or predicate must be set

Error message

Either location or predicate must be set

What it means

HotDeploymentWatchedFileBuildItem tells live-reload which files to watch. Each item must watch something concrete: either a location string or a location predicate. The private constructor enforces that at least one is set; if both are null it throws IllegalArgumentException rather than producing a useless watch entry.

Source

Thrown at core/deployment/src/main/java/io/quarkus/deployment/builditem/HotDeploymentWatchedFileBuildItem.java:57

     * @see #builder()
     */
    public HotDeploymentWatchedFileBuildItem(String location) {
        this(location, true);
    }

    /**
     *
     * @param location
     * @param restartNeeded
     * @see #builder()
     */
    public HotDeploymentWatchedFileBuildItem(String location, boolean restartNeeded) {
        this(location, null, restartNeeded);
    }

    private HotDeploymentWatchedFileBuildItem(String location, Predicate<String> locationPredicate, boolean restartNeeded) {
        if (location == null && locationPredicate == null) {
            throw new IllegalArgumentException("Either location or predicate must be set");
        }
        this.location = location;
        this.locationPredicate = locationPredicate;
        this.restartNeeded = restartNeeded;
    }

    /**
     *
     * @return a location a file from a reloadable module
     */
    public String getLocation() {
        return location;
    }

    public boolean hasLocation() {
        return location != null;
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a real file location, e.g. new HotDeploymentWatchedFileBuildItem("config/application.yaml", true).
  2. If matching multiple paths, use HotDeploymentWatchedFileBuildItem.builder().setLocationPredicate(path -> path.startsWith("config/"))...build().
  3. Guard call sites: skip producing the build item entirely when the configured location is null/blank instead of constructing it.

Example fix

// before
String loc = config.watchedFile(); // may be null
buildProducer.produce(new HotDeploymentWatchedFileBuildItem(loc, true));
// after
String loc = config.watchedFile();
if (loc != null) {
    buildProducer.produce(new HotDeploymentWatchedFileBuildItem(loc, true));
}
Defensive patterns

Strategy: validation

Validate before calling

if (location == null && predicate == null) {
    return; // skip producing the watch item
}
buildProducer.produce(new HotDeploymentWatchedFileBuildItem(location, restartNeeded));

Type guard

boolean isValidWatchTarget(String location, java.util.function.Predicate<String> predicate) {
    return location != null || predicate != null;
}

Try / catch

try {
    produce(new HotDeploymentWatchedFileBuildItem(loc, true));
} catch (IllegalArgumentException e) {
    if ("Either location or predicate must be set".equals(e.getMessage())) {
        log.warn("No watched file configured; skipping hot-deploy watch");
        return;
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling new HotDeploymentWatchedFileBuildItem(null, restartNeeded) (or the two-arg location variant with a null location), so neither location nor predicate is provided.

Common situations: Config-driven code passing an application property straight into the constructor where the property is unset; a builder path that computed a null location and null predicate from an empty config map.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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