pact-jvm icon indicating copy to clipboard operation
pact-jvm copied to clipboard

Pact in instrumented Android tests fails due to SaxParser conflict

Open SanityResort opened this issue 3 years ago • 2 comments

This simple example run as instrumented test in an Android project

import au.com.dius.pact.consumer.ConsumerPactBuilder
import org.junit.Test


class PactTest {

    @Test
    fun pact() {

        ConsumerPactBuilder
            .consumer("An Android App")
            .hasPactWith("A Backend")
            .uponReceiving("a request")

    }
}

causes the following stacktrace

java.lang.ExceptionInInitializerError
	at org.apache.tika.mime.MimeTypesFactory.create(MimeTypesFactory.java:69)
	at org.apache.tika.mime.MimeTypesFactory.create(MimeTypesFactory.java:100)
	at org.apache.tika.mime.MimeTypesFactory.create(MimeTypesFactory.java:189)
	at org.apache.tika.mime.MimeTypes.getDefaultMimeTypes(MimeTypes.java:604)
	at org.apache.tika.config.TikaConfig.getDefaultMimeTypes(TikaConfig.java:80)
	at org.apache.tika.config.TikaConfig.<init>(TikaConfig.java:246)
	at au.com.dius.pact.core.model.OptionalBody.<clinit>(OptionalBody.kt:188)
	at au.com.dius.pact.core.model.OptionalBody.missing(Unknown Source:0)
	at au.com.dius.pact.consumer.dsl.PactDslRequestBase.<init>(PactDslRequestBase.java:30)
	at au.com.dius.pact.consumer.dsl.PactDslRequestWithoutPath.<init>(PactDslRequestWithoutPath.java:40)
	at au.com.dius.pact.consumer.dsl.PactDslWithState.uponReceiving(PactDslWithState.java:41)
	at au.com.dius.pact.consumer.dsl.PactDslWithProvider.uponReceiving(PactDslWithProvider.java:74)
	at de.swmh.oneapp.news.feed.PactTest.pact(PactTest.kt:15)
	at java.lang.reflect.Method.invoke(Native Method)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
	at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)
Caused by: java.lang.RuntimeException: problem initializing SAXParser pool
	at org.apache.tika.mime.MimeTypesReader.<clinit>(MimeTypesReader.java:119)
	... 40 more
Caused by: org.apache.tika.exception.TikaException: prooblem creating SAX parser factory
	at org.apache.tika.mime.MimeTypesReader.newSAXParser(MimeTypesReader.java:396)
	at org.apache.tika.mime.MimeTypesReader.setPoolSize(MimeTypesReader.java:380)
	at org.apache.tika.mime.MimeTypesReader.<clinit>(MimeTypesReader.java:117)
	... 40 more
Caused by: org.xml.sax.SAXNotRecognizedException: http://javax.xml.XMLConstants/feature/secure-processing
	at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:93)
	at org.apache.tika.mime.MimeTypesReader.newSAXParser(MimeTypesReader.java:392)
	... 42 more

Pact version: au.com.dius.pact:consumer:4.1.10 Emulator API levels: 28, 29, 30

The SaxParserfactoryImpl used by the android runtime does not recognize the feature http://javax.xml.XMLConstants/feature/secure-processing and fails with the above exception. The call originates from the instantiation of TikaConfig

SanityResort avatar Nov 11 '20 12:11 SanityResort