From e7e8ab83695fc5926a19dfc302a0853fb2e670bb Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 8 Mar 2022 10:03:46 +0200 Subject: [PATCH] Avoid NPE when RESTEasy Reactive is used together with the classic REST client Fixes: #24120 (cherry picked from commit d3fd924b31680bc631c85b9f4f56523dce6ff6eb) --- .../resteasy/reactive/common/headers/HeaderUtil.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java index c58ee1395ecbb..5a62bddfb6c3b 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java @@ -28,9 +28,10 @@ /** * These work for MultivaluedMap with String and Object */ +@SuppressWarnings({ "rawtypes", "unchecked" }) public class HeaderUtil { - private static final ClassValue HEADER_DELEGATE_CACHE = new ClassValue() { + private static final ClassValue> HEADER_DELEGATE_CACHE = new ClassValue<>() { @Override protected RuntimeDelegate.HeaderDelegate computeValue(Class type) { return RuntimeDelegate.getInstance().createHeaderDelegate(type); @@ -41,7 +42,11 @@ public static String headerToString(Object obj) { if (obj instanceof String) { return (String) obj; } else { - return HEADER_DELEGATE_CACHE.get(obj.getClass()).toString(obj); + RuntimeDelegate.HeaderDelegate delegate = HEADER_DELEGATE_CACHE.get(obj.getClass()); + if (delegate != null) { + return delegate.toString(obj); + } + return obj.toString(); } }