{"record":{"id":"7d062e5501a9f804","repo":"quarkusio/quarkus","slug":"param-was-null-7d062e","errorCode":null,"errorMessage":"param was null","messagePattern":"param was null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/CacheControlDelegate.java","lineNumber":84,"sourceCode":"            } else {\n                if (val == null)\n                    val = \"\";\n                result.getCacheExtension().put(name, val);\n            }\n        }\n        return result;\n    }\n\n    private static StringBuilder addDirective(String directive, StringBuilder buffer) {\n        if (buffer.length() > 0)\n            buffer.append(\", \");\n        buffer.append(directive);\n        return buffer;\n    }\n\n    public String toString(CacheControl value) {\n        if (value == null)\n            throw new IllegalArgumentException(\"param was null\");\n        StringBuilder buffer = new StringBuilder();\n        if (value.isNoCache()) {\n            List<String> fields = value.getNoCacheFields();\n            if (fields.size() < 1) {\n                addDirective(\"no-cache\", buffer);\n            } else {\n                for (String field : value.getNoCacheFields()) {\n                    addDirective(\"no-cache\", buffer).append(\"=\\\"\").append(field).append(\"\\\"\");\n                }\n            }\n        }\n        if (value instanceof ExtendedCacheControl) {\n            ExtendedCacheControl ecc = (ExtendedCacheControl) value;\n            if (ecc.isPublic()) {\n                addDirective(\"public\", buffer);\n            }\n        }\n        if (value.isMustRevalidate())","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/CacheControlDelegate.java#L66-L102","documentation":"CacheControlDelegate.toString(CacheControl) serializes a CacheControl object into a Cache-Control header string. The JAX-RS HeaderDelegate contract mandates IllegalArgumentException when the object to serialize is null.","triggerScenarios":"Passing a null CacheControl to CacheControlDelegate.INSTANCE.toString(null), e.g. when building a response header from a value that failed to initialize.","commonSituations":"Cache-control settings loaded from config that resolved to null; conditional header-building code that forgot the null case; unit tests exercising the delegate with null.","solutions":["Null-check the CacheControl before serializing and skip setting the header when null","Initialize a default CacheControl (e.g. new CacheControl()) instead of leaving null","Use Optional<CacheControl> and only write the header if present","Fix the code path that produces the null object"],"exampleFix":"// before\nString header = CacheControlDelegate.INSTANCE.toString(cacheControl); // NPE-style failure on null\n// after\nif (cacheControl != null) {\n    response.header(\"Cache-Control\", CacheControlDelegate.INSTANCE.toString(cacheControl));\n}","handlingStrategy":"type-guard","validationCode":"if (cacheControl == null) { /* skip setting header */ }","typeGuard":"boolean isSerializable(CacheControl cc) { return cc != null; }","tryCatchPattern":"try {\n    String h = CacheControlDelegate.INSTANCE.toString(cc);\n} catch (IllegalArgumentException e) {\n    // null CacheControl; omit header or substitute default\n}","preventionTips":["Initialize CacheControl objects before serialization","Skip header emission when the object is null","Use Optional<CacheControl> in header-building code"],"tags":["jaxrs","http-headers","cache-control","null-check"],"backgroundTag":"null-header-value","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}