quarkusio/quarkus · warning · IllegalArgumentException

Param was null

Error message

Param was null

What it means

UriBuilderImpl.uriTemplate validates its input and throws IllegalArgumentException('Param was null') when the given URI template CharSequence is null, per the JAX-RS UriBuilder contract which forbids null template strings.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java:164

    public static UriBuilderImpl fromTemplate(String uriTemplate) {
        UriBuilderImpl impl = (UriBuilderImpl) RuntimeDelegate.getInstance().createUriBuilder();
        impl.uriTemplate(uriTemplate);
        return impl;
    }

    private static final Pattern hostPortPattern = Pattern.compile("([^/:]+):(\\d+)");
    private static final Pattern squareHostBrackets = Pattern
            .compile("(\\[(([0-9A-Fa-f]{0,4}:){2,7})([0-9A-Fa-f]{0,4})%?.*\\]):(\\d+)");

    /**
     * You may put path parameters anywhere within the uriTemplate except port.
     *
     * @param uriTemplate uri template
     * @return uri builder
     */
    public UriBuilder uriTemplate(CharSequence uriTemplate) {
        if (uriTemplate == null)
            throw new IllegalArgumentException("Param was null");
        Matcher opaque = opaqueUri.matcher(uriTemplate);
        if (opaque.matches()) {
            this.authority = null;
            this.host = null;
            this.port = -1;
            this.userInfo = null;
            this.query = null;
            this.scheme = opaque.group(1);
            this.ssp = opaque.group(2);
            return this;
        } else {
            Matcher match = hierarchicalUri.matcher(uriTemplate);
            if (match.matches()) {
                ssp = null;
                return parseHierarchicalUri(uriTemplate, match);
            }
        }
        throw new IllegalArgumentException("Illegal URI template" + uriTemplate);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Null-check or default the template/variable before passing it to UriBuilder
  2. If the value comes from config, validate it at startup (fail fast on missing property)
  3. Use Optional.map/orElse to supply a safe default before building the URI
  4. Wrap URI construction in try-catch (IllegalArgumentException) when input is user/environment-derived

Example fix

// before
String base = config.baseUrl(); // may be null
URI u = UriBuilder.fromUri(base).path("/api").build(); // IllegalArgumentException
// after
Objects.requireNonNull(config.baseUrl(), "baseUrl config must be set");
URI u = UriBuilder.fromUri(config.baseUrl()).path("/api").build();
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(template, "URI template must not be null");
// or for variables:
templates.values().removeIf(Objects::isNull);

Type guard

boolean validTemplate(CharSequence t) { return t != null && !t.toString().isBlank(); }

Try / catch

try {
    return UriBuilder.fromUri(template).path(path).build();
} catch (IllegalArgumentException e) {
    log.error("Invalid URI input: " + e.getMessage());
    return null;
}

Prevention

When it happens

Trigger: Passing null to UriBuilder.fromTemplate(null), uri(null), uriFromCharSequence(null), or resolveTemplates/resolveTemplate/resolveTemplateFromEncoded with a null template; commonly a null variable that was interpolated into a template argument.

Common situations: Building client URLs from configuration values that are unset (null base URI); resolveTemplate with a variable that failed lookup; Optional value not unwrapped before building a URI.

Related errors


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