Investigate Dalvik compatibility
jakubadamw opened this issue · comments
This library currently does not work on Dalvik, due to the VM's poor support for XML schemas.
Here's a stack trace I get on instantiating a Srx2SaxParser:
Caused by: java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema
at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:192)
at net.sourceforge.segment.util.Util.getSchema(Util.java:265)
at net.sourceforge.segment.util.Util.getSchema(Util.java:247)
at net.sourceforge.segment.srx.io.Srx2SaxParser.<init>(Srx2SaxParser.java:181)
Let me know if you need any more information.
Thank you for bug report. I currently don't develop on Android / Dalvik, so I wasn't aware of the issue.
Can I suggest to try the following:
- Disable the validation on Dalvik (or everywhere). To do this create Srx2SaxParser as follows:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(Srx2SaxParser.VALIDATE_PARAMETER, false);
SrxParser parser = new Srx2SaxParser(parameters);
- Use other parsers - Srx2Parser (which uses JAXB, always validating, so probably won't work) or Srx2StaxParser (which uses STAX, no validation, so probably will work).
Since Dalvik's XML APIs do not support schema validation, there's probably not much I can do except using custom library to do it.
It's all looking promising, thanks. I successfully followed your first suggestion. All the extra changes I've had to make are in https://github.com/languagetool-org/languagetool, so I'm gonna go ahead and close this issue.
Resolution – Segment works on Android.
Cool, I am glad I could help.
Actually, should we consider improving the scenario of using the library on Android with validation enabled such that it raises a more comprehensible exception?
Well, I think it's Adnroid / Dalvik developers job to make the error more clear. It's quite weird that they don't support XMLSchema.
Nevertheless, feel free to send me a pull request - I don't currently develop on Android so I won't do it. Let me know whether you are interested in contributing, I will close the ticket otherwise.