Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pact in instrumented Android tests fails due to SaxParser conflict #1245

Open
SanityResort opened this issue Nov 11, 2020 · 2 comments
Open

Comments

@SanityResort
Copy link

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

@uglyog
Copy link
Member

uglyog commented Nov 15, 2020

There is not much I can do about this as it is in Apache Tika code and outside my control. I also don't have an Android project to verify. The only thing I can do is catch the exception and then disable content type detection. You'll have to make sure you set the correct content type headers.

The other thing to do is not run it as an instrumented test, but just a normal unit test. I have done this on Android projects in the past.

uglyog pushed a commit that referenced this issue Nov 15, 2020
@uglyog
Copy link
Member

uglyog commented Nov 15, 2020

4.1.11 has been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants