quarkusio/quarkus · error · IllegalArgumentException
Segment is null
Error message
Segment is null
What it means
UriBuilder.segment(String...) throws IllegalArgumentException when any element of the segments array is null. The JAX-RS UriBuilder contract requires all path segments to be non-null strings, and RESTEasy Reactive's implementation enforces this eagerly instead of producing a broken URI later.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java:1051
public String getPath() {
return path;
}
public String getQuery() {
return query;
}
public String getFragment() {
return fragment;
}
public UriBuilder segment(String... segments) throws IllegalArgumentException {
if (segments == null)
throw new IllegalArgumentException("Segment parameter is null");
for (String segment : segments) {
if (segment == null)
throw new IllegalArgumentException("Segment is null");
path(Encode.encodePathSegment(segment));
}
return this;
}
public URI buildFromEncoded(Object... values) throws IllegalArgumentException, UriBuilderException {
if (values == null)
throw new IllegalArgumentException("Values is null");
return buildFromValues(false, true, values);
}
public UriBuilder replacePath(String path) {
if (path == null) {
this.path = null;
return this;
}
this.path = Encode.encodePath(path);
return this;View on GitHub (pinned to e1c734241f)
Solutions
- Filter or substitute null segments before calling segment(), e.g. stream.filter(Objects::nonNull).toArray(String[]::new)
- Provide a default value for optional parts (e.g. Objects.requireNonNullElse(part, "default"))
- Validate inputs at the boundary of your code and fail with a meaningful message before building the URI
- If the segment may be absent, skip the call entirely or use a builder branch that omits it
Example fix
// before
URI uri = UriBuilder.fromUri(base).segment("api", version, "users").build(); // version == null -> IllegalArgumentException
// after
URI uri = UriBuilder.fromUri(base)
.segment("api", Objects.requireNonNullElse(version, "v1"), "users")
.build(); Defensive patterns
Strategy: validation
Validate before calling
if (segments == null || Arrays.stream(segments).anyMatch(Objects::isNull)) {
throw new IllegalArgumentException("segments must not contain nulls");
}
uriBuilder.segment(segments); Type guard
boolean hasNoNulls(String[] arr) {
return arr != null && Arrays.stream(arr).allMatch(Objects::nonNull);
} Try / catch
try {
uriBuilder.segment(segments);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid URI segment (null element in " + Arrays.toString(segments) + ")", e);
} Prevention
- Use Objects.requireNonNullElse to default optional segments
- Filter nulls with a stream before calling segment()
- Validate user/config-supplied path parts at the boundary
- Prefer building paths from non-null typed values (records/enums)
When it happens
Trigger: Calling UriBuilderImpl.segment(...) with a String[] that contains a null element, e.g. uriBuilder.segment("a", null, "b") or passing an array whose entries were not initialized. (Passing a null array raises 'Segment parameter is null' instead.)
Common situations: Building URIs from user input, request parameters, config values, or database fields where one part is null; assembling path parts from optional variables or a List.toArray() of a list containing nulls.
Related errors
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/082a4165d157ba0d.
Report an issue: GitHub.