This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.6.x-fixes by this push:
new 3fa2e40ccf5 CXF-9285: Fix the precompiled NamespaceMapper method name
and a null mapper class
3fa2e40ccf5 is described below
commit 3fa2e40ccf58aa389c59956b75d48b6b3f4e75b3
Author: Freeman Fang <[email protected]>
AuthorDate: Thu Dec 3 12:29:02 2026 -0500
CXF-9285: Fix the precompiled NamespaceMapper method name and a null mapper
class
- the precompiled NamespaceMapper named its method setContextualNamespace
while DataWriterImpl calls setContextualNamespaceDecls, so the contextual
namespaces were not applied when it was used; the old name is kept as a
deprecated alias
- ClassLoaderProxyService logged an NPE at WARNING, and DataWriterImpl a
second WARNING, when no mapper class was available
---
.../apache/cxf/common/jaxb/NamespaceMapper.java | 14 ++--
.../cxf/common/spi/ClassLoaderProxyService.java | 4 ++
.../common/spi/ClassLoaderProxyServiceTest.java | 80 ++++++++++++++++++++++
.../org/apache/cxf/jaxb/io/DataWriterImpl.java | 3 +
4 files changed, 97 insertions(+), 4 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/common/jaxb/NamespaceMapper.java
b/core/src/main/java/org/apache/cxf/common/jaxb/NamespaceMapper.java
index 610d1af6b8c..612c8ad939a 100644
--- a/core/src/main/java/org/apache/cxf/common/jaxb/NamespaceMapper.java
+++ b/core/src/main/java/org/apache/cxf/common/jaxb/NamespaceMapper.java
@@ -44,13 +44,19 @@ public final class NamespaceMapper extends
NamespacePrefixMapper {
return suggestion;
}
- public void setContextualNamespace(String[] contextualNamespaceDecls) {
+ public void setContextualNamespaceDecls(String[] contextualNamespaceDecls)
{
this.nsctxt = contextualNamespaceDecls;
}
+ /**
+ * @deprecated use {@link #setContextualNamespaceDecls(String[])}, which
is the method the JAXB data binding calls
+ */
+ @Deprecated
+ public void setContextualNamespace(String[] contextualNamespaceDecls) {
+ setContextualNamespaceDecls(contextualNamespaceDecls);
+ }
+
public String[] getContextualNamespaceDecls() {
return nsctxt;
}
-
-
-}
\ No newline at end of file
+}
diff --git
a/core/src/main/java/org/apache/cxf/common/spi/ClassLoaderProxyService.java
b/core/src/main/java/org/apache/cxf/common/spi/ClassLoaderProxyService.java
index aed992250bb..9d178cfa4a3 100644
--- a/core/src/main/java/org/apache/cxf/common/spi/ClassLoaderProxyService.java
+++ b/core/src/main/java/org/apache/cxf/common/spi/ClassLoaderProxyService.java
@@ -38,6 +38,10 @@ public class ClassLoaderProxyService implements
ClassLoaderService {
@Override
public Object createNamespaceWrapperInstance(Class<?> mcls, Map<String,
String> map) {
Class<?> cls = srv.createNamespaceWrapperClass(mcls, map);
+ if (cls == null) {
+ // no mapper for this JAXB runtime, the creator has already logged
why if it is unexpected
+ return null;
+ }
try {
return cls.getConstructor(Map.class).newInstance(map);
} catch (Throwable e) {
diff --git
a/core/src/test/java/org/apache/cxf/common/spi/ClassLoaderProxyServiceTest.java
b/core/src/test/java/org/apache/cxf/common/spi/ClassLoaderProxyServiceTest.java
new file mode 100644
index 00000000000..67ea5173099
--- /dev/null
+++
b/core/src/test/java/org/apache/cxf/common/spi/ClassLoaderProxyServiceTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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.spi;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.jaxb.NamespaceMapper;
+import org.apache.cxf.common.util.ReflectionUtil;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class ClassLoaderProxyServiceTest {
+ private static final Map<String, String> PREFIXES =
Collections.singletonMap("urn:a", "a");
+
+ @Test
+ public void testNoMapperClassIsNotAWarning() {
+ Logger log = Logger.getLogger(ClassLoaderProxyService.class.getName());
+ LogRecord[] warning = new LogRecord[1];
+ Handler handler = new Handler() {
+ @Override
+ public void publish(LogRecord r) {
+ if (r.getLevel().intValue() >= Level.WARNING.intValue()) {
+ warning[0] = r;
+ }
+ }
+ @Override
+ public void flush() {
+ }
+ @Override
+ public void close() {
+ }
+ };
+ log.addHandler(handler);
+ try {
+ assertNull(new ClassLoaderProxyService((mcls, map) -> null)
+ .createNamespaceWrapperInstance(Object.class, PREFIXES));
+ assertNull(warning[0] == null ? null : warning[0].getMessage(),
warning[0]);
+ } finally {
+ log.removeHandler(handler);
+ }
+ }
+
+ @Test
+ public void testPrecompiledMapperHasTheMethodTheDataBindingCalls() throws
Exception {
+ // DataWriterImpl calls setContextualNamespaceDecls(String[]) by
reflection
+ NamespaceMapper mapper = new NamespaceMapper(PREFIXES);
+ String[] decls = {"a", "urn:a"};
+ assertNotNull(ReflectionUtil.getDeclaredMethod(NamespaceMapper.class,
"setContextualNamespaceDecls",
+ new Class<?>[]
{String[].class}));
+ ReflectionUtil.getDeclaredMethod(NamespaceMapper.class,
"setContextualNamespaceDecls",
+ new Class<?>[]
{String[].class}).invoke(mapper, new Object[] {decls});
+ assertArrayEquals(decls, mapper.getContextualNamespaceDecls());
+ }
+}
diff --git
a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
index a974ff6a8cc..135302e6fa6 100644
---
a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
+++
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
@@ -200,6 +200,9 @@ public class DataWriterImpl<T> extends JAXBDataBase
implements DataWriter<T> {
//REVISIT should this go into JAXBUtils?
private static void setContextualNamespaceDecls(Object mapper, Map<String,
String> nsctxt) {
+ if (mapper == null) {
+ return;
+ }
try {
Method m = ReflectionUtil.getDeclaredMethod(mapper.getClass(),
"setContextualNamespaceDecls", new Class<?>[]{String[].class});