Details
Description
I am in need of running multiple instances of ivy in parallel from within the same jvm. When I do this I am seeing the following exception:
org.xml.sax.SAXException: FWK005 parse may not be called while parsing.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:253)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:153)
at org.apache.ivy.util.XMLHelper.parseToDom(XMLHelper.java:198)
at org.apache.ivy.plugins.parser.m2.PomReader.<init>(PomReader.java:94)
at org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser.parseDescriptor(PomModuleDescriptorParser.java:115)
at org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser.parseDescriptor(PomModuleDescriptorParser.java:105)
at org.apache.ivy.core.cache.DefaultRepositoryCacheManager$MyModuleDescriptorProvider.provideModule(DefaultRepositoryCacheManager.java:638)
at org.apache.ivy.core.cache.ModuleDescriptorMemoryCache.getStale(ModuleDescriptorMemoryCache.java:68)
at org.apache.ivy.core.cache.DefaultRepositoryCacheManager.getStaledMd(DefaultRepositoryCacheManager.java:655)
at org.apache.ivy.core.cache.DefaultRepositoryCacheManager.cacheModuleDescriptor(DefaultRepositoryCacheManager.java:942)
at org.apache.ivy.plugins.resolver.BasicResolver.parse(BasicResolver.java:542)
at org.apache.ivy.plugins.resolver.BasicResolver.getDependency(BasicResolver.java:263)
at org.apache.ivy.plugins.resolver.IBiblioResolver.getDependency(IBiblioResolver.java:501)
at org.apache.ivy.plugins.resolver.ChainResolver.getDependency(ChainResolver.java:130)
at org.apache.ivy.plugins.resolver.ChainResolver.getDependency(ChainResolver.java:130)
at org.apache.ivy.core.resolve.IvyNode.loadData(IvyNode.java:170)
at org.apache.ivy.core.resolve.VisitNode.loadData(VisitNode.java:274)
at org.apache.ivy.core.resolve.ResolveEngine.fetchDependencies(ResolveEngine.java:671)
at org.apache.ivy.core.resolve.ResolveEngine.doFetchDependencies(ResolveEngine.java:757)
at org.apache.ivy.core.resolve.ResolveEngine.fetchDependencies(ResolveEngine.java:679)
at org.apache.ivy.core.resolve.ResolveEngine.getDependencies(ResolveEngine.java:551)
at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:235)
at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:193)
at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:138)
at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:134)
at org.apache.ivy.Ivy.resolve(Ivy.java:473)
It seems that the DocumentBuilder created in org.apache.ivy.util.XMLHelper.getDocBuilder(EntityResolver) is stored in a static variable and only initialized once. Would it be possible to cache the DocumentBuilderFactory rather then the DocumentBuilder? Doing this would allow for parallel XML parsing. Additionally the entity resolver provided on the first call is the only one used for the lifetime of the DocumentBuilder. I don't know if this was intended, but the method signature does not seem to suggest it.