Re: Runtime ClassCastException on class org.apache.xerces.dom.ElementNSImpl
robertlazarski <[email protected]> Wed, 27 Sep 2023 10:45:32 -1000
| Newsgroups | gmane.text.xml.xerces-j.user |
|---|---|
| Message-ID | <CABpPLBU6XhXN445GGm1rZ342Zf-oB+H9Sc0VuXEM_txSUcLrGQ@mail.gmail.com> |
--00000000000076314706065d4620 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the reply. For the record I confirmed this error happens on xercesImpl-2.12.2.jar. While I too am somewhat amazed this cast ever worked, it did actually work for 10 years starting on this Rampart commit below. " commit b73690eefaad9027bb9633a20e29a218a1021cc9 (HEAD -> master) Author: Amila Jayasekara <[email protected]> Date: Thu Mar 8 08:11:32 2012 +0000 Refactored SAML2TokenIssuer and cleaned up code. Created a test framework to write unit tests for trust scenarios. Fixed documentation errors. Reduced code duplication. Added more tests. " I see that OMNode at runtime ends up being an Axiom class DOOMNSAwareElementImpl that "extends CoreElementImpl" , which implements "org.w3c.dom.Element" - that to me explains why it compiles. So, this is a runtime issue on code that worked fine for a long time. Before I figure out how to rewrite the code in question as I'm not really sure, I thought I'd ask why this happened all of sudden on the Xerces side as I have no clue on the Axiom side. On Wed, Sep 27, 2023 at 9:03=E2=80=AFAM Rick Brown <[email protected]> wro= te: > Ill throe this in, but i might be out in left field (or iut in da weeds) > But this is a difference between axiom and DOM > When working with JAXB and axis2 we had to be very specific as to which > "space" we were in > Axiom or DOM > > you cant just cast between them > > Rick Brown > > On Wednesday, September 27, 2023 at 01:30:53 PM CDT, robertlazarski < > [email protected]> wrote: > > > 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 =3D ... > // OpenSAML assertion defined as <saml> with org.w3c.dom.Element > Element assertionElement =3D 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 i= n > 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/ram= part-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. > --00000000000076314706065d4620 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div><span style=3D"font-family:monospace"><span style=3D"= color:rgb(0,0,0);background-color:rgb(255,255,255)">Thanks for the reply. F= or the record I confirmed this error happens on xercesImpl-2.12.2.jar. <br>= </span></span></div><div><span style=3D"font-family:monospace"><span style= =3D"color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></span></span><= /div><div><span style=3D"font-family:monospace"><span style=3D"color:rgb(0,= 0,0);background-color:rgb(255,255,255)">While I too am somewhat amazed this= cast ever worked, it did actually work for 10 years starting on this Rampa= rt commit below.</span></span></div><div><span style=3D"font-family:monospa= ce"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)"><br>= </span></span></div><div><span style=3D"font-family:monospace"><span style= =3D"color:rgb(0,0,0);background-color:rgb(255,255,255)">"<br></span></= span></div><div><div><span style=3D"font-family:monospace"><span style=3D"c= olor:rgb(178,104,24);background-color:rgb(255,255,255)">commit b73690eefaad= 9027bb9633a20e29a218a1021cc9 (</span><span style=3D"font-weight:bold;color:= rgb(84,255,255);background-color:rgb(255,255,255)">HEAD -> </span><span = style=3D"font-weight:bold;color:rgb(84,255,84);background-color:rgb(255,255= ,255)">master</span><span style=3D"color:rgb(178,104,24);background-color:r= gb(255,255,255)">)</span><span style=3D"color:rgb(0,0,0);background-color:r= gb(255,255,255)"> </span><br>Author: Amila Jayasekara <<a href=3D"mailto:[email protected]= " target=3D"_blank">[email protected]</a>> <br>Date: =C2=A0=C2=A0Thu Mar 8 08:11:32 2012 +0000 <br> <br> =C2=A0=C2=A0=C2=A0Refactored SAML2TokenIssuer and cleaned up code. Cre= ated a test framework to write unit tests for trust scenarios. Fixed docume= ntation errors. Reduced code duplication. Added more tests.</span></div><di= v><span style=3D"font-family:monospace">"</span></div><div><span style= =3D"font-family:monospace"><br></span></div></div><div><span style=3D"font-= family:monospace"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,= 255,255)">I see that OMNode at runtime ends up being an Axiom class </span>= </span><span style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0= );background-color:rgb(255,255,255)">DOOMNSAwareElementImpl that "</sp= an><span style=3D"color:rgb(135,255,175);background-color:rgb(255,255,255)"= >extends</span><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255= ,255)"> CoreElementImpl" , which implements "</span></span><span = style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);background-= color:rgb(255,255,255)">org.w3c.dom.Element" - that to me explains why= it compiles. </span><br></span><br></div><div><span style=3D"font-family:m= onospace"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)= ">So, this is a runtime issue on code that worked fine for a long time.=C2= =A0</span></span></div><div><span style=3D"font-family:monospace"><span sty= le=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></span></span= ></div><div><span style=3D"font-family:monospace"><span style=3D"color:rgb(= 0,0,0);background-color:rgb(255,255,255)">Before I figure out how to rewrit= e the code in question as I'm not really sure, I thought I'd ask wh= y this happened all of sudden on the Xerces side as I have no clue on the A= xiom side. =C2=A0 </span></span></div><br><div><span style=3D"font-family:m= onospace"></span></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr= " class=3D"gmail_attr">On Wed, Sep 27, 2023 at 9:03=E2=80=AFAM Rick Brown &= lt;<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]= et</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margi= n:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex= "><div><div style=3D"font-family:Helvetica Neue,Helvetica,Arial,sans-serif;= font-size:16px"><div></div> <div>Ill throe this in, but i might be out in left field (or iut in= da weeds)</div><div>But this is a difference between axiom and DOM</div><d= iv>When working with JAXB and axis2 we had to be very specific as to which = "space" we were in</div><div>Axiom or DOM</div><div><br></div><di= v>you cant just cast between them</div><div><br></div><div>Rick Brown</div>= <div><br></div> =20 <div id=3D"m_-5365263205531194603m_3558140001034825098ydp81f5c5e9ya= hoo_quoted_6628126962"> <div style=3D"font-family:"Helvetica Neue",Helvetica,= Arial,sans-serif;font-size:13px;color:rgb(38,40,42)"> =20 <div> On Wednesday, September 27, 2023 at 01:30:53 PM CDT, ro= bertlazarski <<a href=3D"mailto:[email protected]" target=3D"_bla= nk">[email protected]</a>> wrote: </div> <div><br></div> <div><br></div> <div><div id=3D"m_-5365263205531194603m_3558140001034825098= ydp81f5c5e9yiv8636611883"><div dir=3D"ltr"><div>I'm the VP of the Apach= e 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 2= 017 - to modern dependencies. <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 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.=C2=A0</div><div><br><= /div><div>However, there is now a ClassCastException running a unit test wh= en casting as shown.=C2=A0</div><div><br></div><div><span style=3D"font-fam= ily:monospace"><span style=3D"color:rgb(95,215,255);background-color:rgb(25= 5,255,255)">import</span><span style=3D"color:rgb(0,0,0);background-color:r= gb(255,255,255)"> org.apache.axiom.om.OMElement;</span></span></div><div><d= iv><span style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);ba= ckground-color:rgb(255,255,255)"></span></span></div><div><span style=3D"fo= nt-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-c= olor:rgb(255,255,255)"> org.apache.axiom.om.OMNode;</span><br></span></div>= </div><div><span style=3D"font-family:monospace"><span style=3D"color:rgb(9= 5,215,255);background-color:rgb(255,255,255)">import</span><span style=3D"c= olor:rgb(0,0,0);background-color:rgb(255,255,255)"> org.w3c.dom.Element;</s= pan></span></div><div><span style=3D"font-family:monospace"><span style=3D"= color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></span></span></div= ><div>// <font color=3D"#000000">defined as <wst:RequestedSecurityT</fon= t>oken></div><div><span style=3D"font-family:monospace"><span style=3D"c= olor:rgb(0,0,0);background-color:rgb(255,255,255)">OMElement requestedSecur= ityTokenElement =3D </span>...</span></div><div>// OpenSAML assertion defin= ed as <saml> <font color=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 asser= tion.getDOM();</span><br></span></div><div>// Boom! <br></div><div><span st= yle=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);background-co= lor:rgb(255,255,255)">requestedSecurityTokenElement.addChild((OMNode)assert= ionElement);</span><br></span></div><div><span style=3D"font-family:monospa= ce"><br></span></div><div><span style=3D"font-family:monospace">Error: <br>= </span></div><div><p><font color=3D"#000000">java.lang.ClassCast</font><fon= t color=3D"#000000">Exce</font><font color=3D"#000000">ption: class org.apa= che.xerces.dom.ElementNSImpl 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 'app') <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" rel=3D"nofollow" target=3D"_blank">https://github.com/apache/ax= is-axis2-java-rampart/blob/master/modules/rampart-trust/src/main/java/org/a= pache/rahas/impl/SAML2TokenIssuer.java#L242</a> <br></p><p>I tried asking t= he most prolific Axiom developer for help in the issue below a few weeks ag= o but got no response. <br></p><p><a href=3D"https://issues.apache.org/jira= /browse/RAMPART-449" rel=3D"nofollow" target=3D"_blank">https://issues.apac= he.org/jira/browse/RAMPART-449</a></p><p>I am asking here because I am stuc= k and need some type of guidance. <br></p></div></div> </div></div> </div> </div></div></div></blockquote></div> --00000000000076314706065d4620--