Runtime ClassCastException on class org.apache.xerces.dom.ElementNSImpl

robertlazarski <[email protected]> Wed, 27 Sep 2023 08:30:29 -1000
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <CABpPLBUMuGv8k4ZSRPs-hRLXqjJsHxvikdV1SGfsR_3UgmPwog@mail.gmail.com>
--00000000000081c95906065b63a5
Content-Type: text/plain; charset="UTF-8"

I'm the VP of the Apache Axis project and on the PMC of the Apache Axiom
project, and I am trying to upgrade the Axis sub project Apache Rampart
project - last released in 2017 - to modern dependencies.

My environment is JDK 17 on Linux with a compiler target of JDK 11.

I mention all this because I have a Rampart unit test that I am trying to
fix. The code compiles fine, git history shows this code has no recent
changes in the area and just always worked.

However, there is now a ClassCastException running a unit test when casting
as shown.

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.w3c.dom.Element;

// defined as <wst:RequestedSecurityToken>
OMElement requestedSecurityTokenElement = ...
// OpenSAML assertion defined as <saml> with org.w3c.dom.Element
Element assertionElement = assertion.getDOM();
// Boom!
requestedSecurityTokenElement.addChild((OMNode)assertionElement);

Error:

java.lang.ClassCastException: class org.apache.xerces.dom.ElementNSImpl cannot
be cast to class org.apache.axiom.om.OMNode
(org.apache.xerces.dom.ElementNSImpl and org.apache.axiom.om.OMNode are in
unnamed module of loader 'app')
       at
org.apache.rahas.impl.SAML2TokenIssuer.createRequestSecurityTokenResponse(SAML2TokenIssuer.java:242)

The code is here.

https://github.com/apache/axis-axis2-java-rampart/blob/master/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java#L242

I tried asking the most prolific Axiom developer for help in the issue
below a few weeks ago but got no response.

https://issues.apache.org/jira/browse/RAMPART-449

I am asking here because I am stuck and need some type of guidance.

--00000000000081c95906065b63a5
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I&#39;m the VP of the Apache Axis project and on the =
PMC of the Apache Axiom project, and I am trying to upgrade the Axis sub pr=
oject Apache Rampart project - last released in 2017 - to modern dependenci=
es. <br></div><div><br></div><div>My environment is JDK 17 on Linux with a =
compiler target of JDK 11.=C2=A0</div><div>=C2=A0<br></div><div>I mention a=
ll this because I have a Rampart unit test that I am trying to fix. The cod=
e compiles fine, git history shows this code has no recent changes in the a=
rea and just always worked.=C2=A0</div><div><br></div><div>However, there i=
s now a ClassCastException running a unit test when casting as shown.=C2=A0=
</div><div><br></div><div><span style=3D"font-family:monospace"><span style=
=3D"color:rgb(95,215,255);background-color:rgb(255,255,255)">import</span><=
span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)"> org.apac=
he.axiom.om.OMElement;</span></span></div><div><div><span style=3D"font-fam=
ily:monospace"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255=
,255)"></span></span></div><div><span style=3D"font-family:monospace"><span=
 style=3D"color:rgb(95,215,255);background-color:rgb(255,255,255)">import</=
span><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)"> or=
g.apache.axiom.om.OMNode;</span><br></span></div></div><div><span style=3D"=
font-family:monospace"><span style=3D"color:rgb(95,215,255);background-colo=
r:rgb(255,255,255)">import</span><span style=3D"color:rgb(0,0,0);background=
-color:rgb(255,255,255)"> org.w3c.dom.Element;</span></span></div><div><spa=
n style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);backgroun=
d-color:rgb(255,255,255)"><br></span></span></div><div>// <font color=3D"#0=
00000">defined as &lt;wst:RequestedSecurityT</font>oken&gt;</div><div><span=
 style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);background=
-color:rgb(255,255,255)">OMElement requestedSecurityTokenElement =3D </span=
>...</span></div><div>// OpenSAML assertion defined as &lt;saml&gt; <font c=
olor=3D"#000000">with org.w3c.dom.Element</font> </div><div><span style=3D"=
font-family:monospace"><span style=3D"color:rgb(0,0,0);background-color:rgb=
(255,255,255)">Element assertionElement =3D assertion.getDOM();</span><br><=
/span></div><div>// Boom! <br></div><div><span style=3D"font-family:monospa=
ce"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)">requ=
estedSecurityTokenElement.addChild((OMNode)assertionElement);</span><br></s=
pan></div><div><span style=3D"font-family:monospace"><br></span></div><div>=
<span style=3D"font-family:monospace">Error: <br></span></div><div><p><font=
 color=3D"#000000">java.lang.ClassCast</font><font color=3D"#000000">Exce</=
font><font color=3D"#000000">ption: class org.apache.xerces.dom.ElementNSIm=
pl can</font>not
 be cast to class org.apache.axiom.om.OMNode=20
(org.apache.xerces.dom.ElementNSImpl and org.apache.axiom.om.OMNode are=20
in unnamed module of loader &#39;app&#39;) <br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0at org.apache.rahas.impl.SAML2Tok=
enIssuer.createRequestSecurityTokenResponse(SAML2TokenIssuer.java:242)</p>


<p>The code is here. </p>

<p><a href=3D"https://github.com/apache/axis-axis2-java-rampart/blob/master=
/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer=
.java#L242" class=3D"external-link" target=3D"_blank" rel=3D"nofollow noope=
ner">https://github.com/apache/axis-axis2-java-rampart/blob/master/modules/=
rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java#L24=
2</a> <br></p><p>I tried asking the most prolific Axiom developer for help =
in the issue below a few weeks ago but got no response. <br></p><p><a href=
=3D"https://issues.apache.org/jira/browse/RAMPART-449">https://issues.apach=
e.org/jira/browse/RAMPART-449</a></p><p>I am asking here because I am stuck=
 and need some type of guidance. <br></p></div></div>

--00000000000081c95906065b63a5--