Freeman Yue Fang created CXF-9285:
-------------------------------------
Summary: NamespaceMapper generation and loading problems: the
load-only setup loses namespace prefixes, an NPE is logged, and the precompiled
mapper's method name doesn't match
Key: CXF-9285
URL: https://issues.apache.org/jira/browse/CXF-9285
Project: CXF
Issue Type: Bug
Components: Core, JAXB Databinding
Reporter: Freeman Yue Fang
CXF generates the JAXB namespace prefix mapper class with ASM
(NamespaceClassGenerator) and, in the load-only setup used by GraalVM native
builds such as Quarkus, loads a class captured at build time
(GeneratedNamespaceClassLoader). There are several problems around this. They
were reported in quarkus-cxf issue 2441.
On 4.x/main:
# GeneratedNamespaceClassLoader looks up
{{org.apache.cxf.jaxb.NamespaceMapper}} for a GlassFish marshaller, while
NamespaceClassGenerator generates {{NamespaceMapperRI}}. The lookup finds
nothing, so with the load-only setup no mapper is set and the configured
namespace prefixes are lost (ns1, ns2, ... are used instead). The MOXy mapper
is only found if it was captured at build time.
# The fallback to the precompiled
{{org.apache.cxf.common.jaxb.NamespaceMapper}} only applies to marshaller
classes whose name contains "com.sun", which never matches on 4.x.
# The generated GlassFish mapper always extends
{{org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper}}, whatever the
marshaller class. So it is a copy of the precompiled NamespaceMapper, and
generating it serves no purpose. cxf-core already has a compile dependency on
jaxb-runtime.
On 3.6.x and 4.x/main:
# ClassLoaderProxyService logs an NPE at WARNING (and DataWriterImpl logs a
second WARNING) when no mapper class is available.
# The precompiled NamespaceMapper names its method {{setContextualNamespace}},
while DataWriterImpl reflectively calls {{setContextualNamespaceDecls}}. So the
contextual namespace declarations are not applied when the precompiled mapper
is used.
Proposed fix (4.x/main):
* Use precompiled mappers only and remove the ASM generation of namespace
mappers:
** {{org.apache.cxf.common.jaxb.NamespaceMapper}} for GlassFish
** a new {{org.apache.cxf.common.jaxb.EclipseNamespaceMapper}} for EclipseLink
MOXy. It is compiled against an optional (provided)
{{org.eclipse.persistence.core}} dependency and imported optionally in OSGi.
* Add a {{ContextualNamespaceMapper}} interface, implemented by both mappers,
which DataWriterImpl calls directly. The reflective call is kept for mappers
supplied by a custom ClassLoaderService.
* Rename the method to {{setContextualNamespaceDecls}} and keep
{{setContextualNamespace}} as a deprecated alias.
* Return null in ClassLoaderProxyService when no mapper class is available, and
skip setting the mapper in DataWriterImpl.
3.6.x: generation is still needed there, because the JAXB RI and JDK-internal
superclasses differ. Only the method name and null handling fixes (items 4 and
5) apply.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)