{"record":{"id":"c1d0cb07652de210","repo":"quarkusio/quarkus","slug":"uri-was-null","errorCode":null,"errorMessage":"URI was null","messagePattern":"URI was 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/LinkBuilderImpl.java","lineNumber":45,"sourceCode":"        return this;\n    }\n\n    @Override\n    public Link.Builder link(String link) {\n        Link l = LinkImpl.valueOf(link);\n        return link(l);\n    }\n\n    @Override\n    public Link.Builder uriBuilder(UriBuilder uriBuilder) {\n        this.uriBuilder = uriBuilder.clone();\n        return this;\n    }\n\n    @Override\n    public Link.Builder uri(URI uri) {\n        if (uri == null)\n            throw new IllegalArgumentException(\"URI was null\");\n        uriBuilder = UriBuilder.fromUri(uri);\n        return this;\n    }\n\n    @Override\n    public Link.Builder uri(String uri) throws IllegalArgumentException {\n        if (uri == null)\n            throw new IllegalArgumentException(\"URI was null\");\n        uriBuilder = UriBuilder.fromUri(uri);\n        return this;\n    }\n\n    @Override\n    public Link.Builder rel(String rel) {\n        if (rel == null)\n            throw new IllegalArgumentException(\"param was null\");\n        final String rels = this.map.get(Link.REL);\n        param(Link.REL, rels == null ? rel : rels + \" \" + rel);","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/LinkBuilderImpl.java#L27-L63","documentation":"Link.Builder.uri(URI) throws IllegalArgumentException when the supplied URI is null. A Web Link requires a target URI; the JAX-RS Link.Builder contract mandates non-null input, so the implementation fails fast rather than producing an invalid link.","triggerScenarios":"Calling Link.fromUri(someUri) / builder.uri(someUri) where the URI variable is null — commonly from an unresolved lookup like UriInfo.getRequestUri() returning null in a test, or a config-derived base URI that was never set.","commonSituations":"Building HATEOAS links where the base URL comes from optional configuration; constructing links from parsed headers that were absent; unit tests that skip URI initialization.","solutions":["Ensure the URI is non-null before building the link; derive a sensible default (e.g. from the current request).","Skip link generation entirely when the target URI is unavailable.","Use uri(String) with a validated string if that fits better, but still null-check first.","Guard helper methods that build links so they return Optional<Link> when the URI is missing."],"exampleFix":"// before\nLink link = Link.fromUri(baseUri).build(); // NPE risk / IllegalArgumentException when baseUri == null\n// after\nif (baseUri == null) {\n    return null; // or a default link\n}\nLink link = Link.fromUri(baseUri).build();","handlingStrategy":"validation","validationCode":"if (uri == null) {\n    // skip or substitute\n    return null;\n}\nLink link = Link.fromUri(uri).build();","typeGuard":"static Optional<Link> linkIfPresent(URI uri) {\n    return Optional.ofNullable(uri).map(u -> Link.fromUri(u).build());\n}","tryCatchPattern":"try {\n    return Link.fromUri(uri).build();\n} catch (IllegalArgumentException e) {\n    if (\"URI was null\".equals(e.getMessage())) {\n        LOG.warn(\"link target URI missing; skipping link\");\n        return null;\n    }\n    throw e;\n}","preventionTips":["Make base URIs required configuration so they are never null.","Return Optional<Link> from link-building helpers.","Null-check URIs parsed from headers before using them for links."],"tags":["jax-rs","link","illegal-argument","null-check","resteasy-reactive"],"backgroundTag":"null-argument-not-allowed","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"}