{"record":{"id":"082a4165d157ba0d","repo":"quarkusio/quarkus","slug":"segment-is-null","errorCode":null,"errorMessage":"Segment is null","messagePattern":"Segment is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java","lineNumber":1051,"sourceCode":"\n    public String getPath() {\n        return path;\n    }\n\n    public String getQuery() {\n        return query;\n    }\n\n    public String getFragment() {\n        return fragment;\n    }\n\n    public UriBuilder segment(String... segments) throws IllegalArgumentException {\n        if (segments == null)\n            throw new IllegalArgumentException(\"Segment parameter is null\");\n        for (String segment : segments) {\n            if (segment == null)\n                throw new IllegalArgumentException(\"Segment is null\");\n            path(Encode.encodePathSegment(segment));\n        }\n        return this;\n    }\n\n    public URI buildFromEncoded(Object... values) throws IllegalArgumentException, UriBuilderException {\n        if (values == null)\n            throw new IllegalArgumentException(\"Values is null\");\n        return buildFromValues(false, true, values);\n    }\n\n    public UriBuilder replacePath(String path) {\n        if (path == null) {\n            this.path = null;\n            return this;\n        }\n        this.path = Encode.encodePath(path);\n        return this;","sourceCodeStart":1033,"sourceCodeEnd":1069,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java#L1033-L1069","documentation":"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.","triggerScenarios":"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.)","commonSituations":"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.","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"],"exampleFix":"// before\nURI uri = UriBuilder.fromUri(base).segment(\"api\", version, \"users\").build(); // version == null -> IllegalArgumentException\n// after\nURI uri = UriBuilder.fromUri(base)\n    .segment(\"api\", Objects.requireNonNullElse(version, \"v1\"), \"users\")\n    .build();","handlingStrategy":"validation","validationCode":"if (segments == null || Arrays.stream(segments).anyMatch(Objects::isNull)) {\n    throw new IllegalArgumentException(\"segments must not contain nulls\");\n}\nuriBuilder.segment(segments);","typeGuard":"boolean hasNoNulls(String[] arr) {\n    return arr != null && Arrays.stream(arr).allMatch(Objects::nonNull);\n}","tryCatchPattern":"try {\n    uriBuilder.segment(segments);\n} catch (IllegalArgumentException e) {\n    throw new IllegalArgumentException(\"Invalid URI segment (null element in \" + Arrays.toString(segments) + \")\", e);\n}","preventionTips":["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)"],"tags":["jax-rs","uri","null-check","resteasy-reactive"],"backgroundTag":"null-argument-illegal-argument","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}