{"record":{"id":"aa5055ef0385514b","repo":"quarkusio/quarkus","slug":"type-cannot-be-null","errorCode":null,"errorMessage":"type cannot be null","messagePattern":"type cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/RuntimeDelegateImpl.java","lineNumber":100,"sourceCode":"    public <T> RestResponse.ResponseBuilder<T> createRestResponseBuilder() {\n        return factory.createRestResponse();\n    }\n\n    @Override\n    public Variant.VariantListBuilder createVariantListBuilder() {\n        return new VariantListBuilderImpl();\n    }\n\n    @Override\n    public <T> T createEndpoint(Application application, Class<T> endpointType)\n            throws IllegalArgumentException, UnsupportedOperationException {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public <T> HeaderDelegate<T> createHeaderDelegate(Class<T> type) throws IllegalArgumentException {\n        if (type == null) {\n            throw new IllegalArgumentException(\"type cannot be null\");\n        }\n        if (type.equals(MediaType.class)) {\n            return (HeaderDelegate<T>) MediaTypeHeaderDelegate.INSTANCE;\n        } else if (Date.class.isAssignableFrom(type)) {\n            // for Date, we do subtypes too, because ORM will instantiate java.util.Date as subtypes\n            // and it's extremely likely we get those here, and we still have to generate a valid\n            // date representation for them, rather than Object.toString which will be wrong\n            return (HeaderDelegate<T>) DateDelegate.INSTANCE;\n        } else if (type.equals(CacheControl.class)) {\n            return (HeaderDelegate<T>) CacheControlDelegate.INSTANCE;\n        } else if (type.equals(NewCookie.class)) {\n            return (HeaderDelegate<T>) NewCookieHeaderDelegate.INSTANCE;\n        } else if (type.equals(Cookie.class)) {\n            return (HeaderDelegate<T>) CookieHeaderDelegate.INSTANCE;\n        } else if (type.equals(EntityTag.class)) {\n            return (HeaderDelegate<T>) EntityTagDelegate.INSTANCE;\n        } else if (type.equals(Locale.class)) {\n            return (HeaderDelegate<T>) LocaleDelegate.INSTANCE;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/RuntimeDelegateImpl.java#L82-L118","documentation":"RuntimeDelegateImpl.createHeaderDelegate requires a non-null Class argument per the JAX-RS RuntimeDelegate contract and throws IllegalArgumentException when type is null. Valid delegates exist for MediaType, Date, CacheControl, Cookie, EntityTag, Link, NewCookie, and URI types; unknown types later throw UnsupportedOperationException.","triggerScenarios":"Calling createHeaderDelegate(null) directly, or indirectly through header serialization code that lost the type (reflection/generic erasure producing a null Class).","commonSituations":"Custom header-param converters resolving a runtime type that is null; framework integrations passing erased generic types; hand-written code building header delegates.","solutions":["Ensure a concrete non-null Class is passed to createHeaderDelegate","If the type comes from generics/reflection, resolve the erased type before the call","Wrap in Objects.requireNonNull(type) early to fail fast with a clearer error","For unsupported types, register a custom HeaderDelegate or convert the value to String yourself"],"exampleFix":"// before\nHeaderDelegate<Foo> d = rd.createHeaderDelegate(genericType); // genericType may be null\n// after\nif (genericType == null) {\n    genericType = value.getClass();\n}\nHeaderDelegate<Foo> d = rd.createHeaderDelegate((Class<Foo>) genericType);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(type, \"header delegate type must not be null\");","typeGuard":"boolean isDelegateSupported(Class<?> type) {\n    return type != null && (MediaType.class.equals(type) || Date.class.isAssignableFrom(type)\n        || CacheControl.class.equals(type) || Cookie.class.equals(type) || EntityTag.class.equals(type)\n        || Link.class.equals(type) || NewCookie.class.equals(type) || URI.class.equals(type));\n}","tryCatchPattern":"try {\n    return rd.createHeaderDelegate(type);\n} catch (IllegalArgumentException e) {\n    return value -> value == null ? null : value.toString();\n}","preventionTips":["Pass concrete classes, never erased generics","Null-check generic type parameters before use","Prefer toString()/serialisation for custom header types","Handle UnsupportedOperationException for unsupported types"],"tags":["jaxrs","runtime-delegate","illegal-argument","null-check"],"backgroundTag":"null-argument-validation","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"}