Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve this AbstractMethodError?

I got below error when I run junit test in the ant. The test class needs call web service API.

Can someone help to resolve it?

<error message="javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z)V" type="java.lang.AbstractMethodError">java.lang.AbstractMethodError: javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z)V
at com.sun.xml.ws.util.xml.XmlUtil.newTransformerFactory(XmlUtil.java:392)
at com.sun.xml.ws.util.xml.XmlUtil.newTransformerFactory(XmlUtil.java:400)
at com.sun.xml.ws.util.xml.XmlUtil.&lt;clinit&gt;(XmlUtil.java:233)
at com.sun.xml.ws.client.WSServiceDelegate.createCatalogResolver(WSServiceDelegate.java:377)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:363)
at com.sun.xml.ws.client.WSServiceDelegate.&lt;init&gt;(WSServiceDelegate.java:321)
at com.sun.xml.ws.client.WSServiceDelegate.&lt;init&gt;(WSServiceDelegate.java:230)
at com.sun.xml.ws.client.WSServiceDelegate.&lt;init&gt;(WSServiceDelegate.java:211)
at com.sun.xml.ws.client.WSServiceDelegate.&lt;init&gt;(WSServiceDelegate.java:207)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:114)
at javax.xml.ws.Service.&lt;init&gt;(Service.java:77)
at com.myorg.mydepart.ws.client.MyAppWs.&lt;init&gt;(AccountManagerWs.java:42)
at ... ...
like image 571
Edmond Wang Avatar asked Aug 22 '26 12:08

Edmond Wang


1 Answers

I just found the root cause by myself.

Per Oracle Documentation, The java.lang.AbstractMethodError is thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

Seems I have not specified the implementation for the abstract class javax.xml.transform.TransformerFactory in the rt.jar.

Adding below inside Junit

<sysproperty key="javax.xml.transform.TransformerFactory"
                        value="com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/>

make it works.

So the final Junit task looks like below:

<junit showoutput="true" printsummary="yes" fork="true" forkmode="once">
            <classpath refid="junit.runtime.classpath" />
            <sysproperty key="javax.xml.transform.TransformerFactory"
                        value="com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/>
            <batchtest haltonfailure="no" todir="${test.result.dir}">
                <fileset dir="${test.src.dir}">
                    <include name="**/*Test.java" />
                </fileset>
                <formatter type="xml" />
            </batchtest>
        </junit>
like image 143
Edmond Wang Avatar answered Aug 24 '26 02:08

Edmond Wang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!