I’m using Smack version 4.3.0, on a Honor9 phone with Android 8. When trying to use the XmlUtil.prettyFormatXml()
method, I get the following crash :
Caused by: java.lang.IllegalArgumentException: Not supported: indent-number
at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:580)
at org.jivesoftware.smack.util.XmlUtil.<clinit>(XmlUtil.java:38)
at org.jivesoftware.smack.util.XmlUtil.prettyFormatXml(XmlUtil.java:42)
at io.nea.workwell.chat.connection.StethoXmppInterceptor.onStanzaReceived(StethoXmppInterceptor.kt:39)
at io.nea.workwell.chat.connection.WorkwellChatConnection$setupXmppConnection$5.processStanza(WorkwellChatConnection.kt:417)
at org.jivesoftware.smack.AbstractXMPPConnection$5.run(AbstractXMPPConnection.java:1198)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
This error happens in the XmlUtil class, in the static initializer :
transformerFactory.setAttribute("indent-number", 2);
The documentation of the setAttribute
method says that
An
IllegalArgumentException
is thrown if the underlying implementation doesn’t recognize the attribute.
This clearly seems to be what’s wrong here, my phone’s implementation doesn’t support the indent-number
attribute. Note that if I disable that line, and keep the rest of the prettyFormatXml()
method, it does work as intended, probably thanks to the line :
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");