This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch coheigea/JAXBContextCache
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 4af66ec7afad4fbfa2fbbc5088dca5ed8262deab
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Wed Nov 25 15:49:50 2026 +0000

    Fix JAXBContextCache exact lookup when there is no default namespace
---
 .../apache/cxf/common/jaxb/JAXBContextCache.java   |  5 +--
 .../cxf/common/jaxb/JAXBContextCacheTest.java      | 37 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/cxf/common/jaxb/JAXBContextCache.java 
b/core/src/main/java/org/apache/cxf/common/jaxb/JAXBContextCache.java
index 79908f1316c..2a9308d5eec 100644
--- a/core/src/main/java/org/apache/cxf/common/jaxb/JAXBContextCache.java
+++ b/core/src/main/java/org/apache/cxf/common/jaxb/JAXBContextCache.java
@@ -205,8 +205,9 @@ public final class JAXBContextCache {
                 if (exact) {
                     cachedContextAndSchemasInternalMap
                         = JAXBCONTEXT_CACHE.get(classes);
-                    if (cachedContextAndSchemasInternalMap != null && 
defaultNs != null) {
-                        cachedContextAndSchemasInternal = 
cachedContextAndSchemasInternalMap.get(defaultNs);
+                    if (cachedContextAndSchemasInternalMap != null) {
+                        cachedContextAndSchemasInternal
+                            = cachedContextAndSchemasInternalMap.get(defaultNs 
!= null ? defaultNs : "");
                     }
                 } else {
                     for (Entry<Set<Class<?>>, Map<String, 
CachedContextAndSchemasInternal>> k
diff --git 
a/core/src/test/java/org/apache/cxf/common/jaxb/JAXBContextCacheTest.java 
b/core/src/test/java/org/apache/cxf/common/jaxb/JAXBContextCacheTest.java
new file mode 100644
index 00000000000..8bfbacfc766
--- /dev/null
+++ b/core/src/test/java/org/apache/cxf/common/jaxb/JAXBContextCacheTest.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.common.jaxb;
+
+import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+public class JAXBContextCacheTest {
+
+    @Test
+    public void testExactLookupWithoutDefaultNamespaceIsCached() throws 
Exception {
+        String pkg = 
org.apache.cxf.configuration.security.ObjectFactory.class.getPackage().getName();
+        ClassLoader loader = getClass().getClassLoader();
+        CachedContextAndSchemas first = 
JAXBContextCache.getCachedContextAndSchemas(pkg, null, loader);
+        CachedContextAndSchemas second = 
JAXBContextCache.getCachedContextAndSchemas(pkg, null, loader);
+        assertSame(first.getContext(), second.getContext());
+    }
+}

Reply via email to