Open scheuchzer opened 5 years ago
Should 3.6.14 still work with Java8? I would expect it to work with Java 8 as it is just a patch level version jump from 3.6.13. Should I open a separate issue for that?
Root cause for the NoSuchMethodError is probably the readBytes method
/**
* Reads this stream completely into a byte array.
*
* **Note**: It is the caller's responsibility to close this stream.
*/
@SinceKotlin("1.3")
public fun InputStream.readBytes(): ByteArray {
val buffer = ByteArrayOutputStream(maxOf(DEFAULT_BUFFER_SIZE, this.available()))
copyTo(buffer)
return buffer.toByteArray()
}
It was introduced in Kotlin 1.3. Pact version 3.6.14 depends on Kotlin 1.2.71. Updating Kotlin in my pom fixes this and it runs with Java8 again
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.3.50</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>1.3.50</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.3.50</version>
</dependency>
Haven't checked if this is also the issue with pact 4.
Related to #949
Would you require Kotlin 1.2 support? Or is it ok to upgrade to 1.3?
Kotlin 1.3 is fine. I only require that it works with Java8 and Spring Boot :-) Seems to be exactly the same as #949. Haven't found that one before.
Kotlin was already in 1.3 but the ktor dependency relies on 1.2. I upgraded ktor to the latest versions that is based on kotlin 1.3.60. see #985
PR build failed because it failed to download the scala-compiler.jar in two cases.
I'm still seeing this with 4.0.9 using JDK 13 (language level 8).
Caused by: java.net.SocketException: Unexpected end of file from server
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:862)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:859)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1610)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:84)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:729)
... 43 more
Using JDK1.8.0_221, I see instead
Exception in thread "Thread-3" java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;)[B
at au.com.dius.pact.consumer.BaseJdkMockServer.toPactRequest(MockHttpServer.kt:227)
at au.com.dius.pact.consumer.BaseJdkMockServer.handle(MockHttpServer.kt:198)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
at sun.net.httpserver.ServerImpl$DefaultExecutor.execute(ServerImpl.java:158)
at sun.net.httpserver.ServerImpl$Dispatcher.handle(ServerImpl.java:431)
at sun.net.httpserver.ServerImpl$Dispatcher.run(ServerImpl.java:396)
at java.lang.Thread.run(Thread.java:748)
@mattkindy-praetorian can you provide the dependencies of your project and the version of Kotlin
There are quite a few dependencies in this particular project, do you need all of them?. How do I get my Kotlin version for a Java project?
No, just need to know what versions of Kotlin and Ktor are being pulled in. If you're using Gradle, you can run gradle dependencies
in your project. For Maven, you need to use the dependency tree plugin.
I've managed to hit this problem again on a Spring Boot 2.1.1, Pact 4.1.7, on Java 11.
Somehow my gradle build ends up resolving the kotlin version to use on my testRuntime scope to 1.2.71 (kotlin is not present on the main runtime scope). See a partial result of gradle dependencies
+--- au.com.dius.pact.consumer:junit:4.1.7
| +--- au.com.dius.pact:consumer:4.1.7
| | +--- org.slf4j:slf4j-api:1.7.28 -> 1.7.25
| | +--- io.ktor:ktor-server-netty:1.3.1
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71 -> 1.3.61
| | | | \--- org.jetbrains:annotations:13.0
| | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61 -> 1.2.71
| | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.71 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61 -> 1.2.71
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.2.71 (*)
| | | | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71 (*)
| | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.60 -> 1.2.71 (*)
| | | | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.60 -> 1.3.61
| | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.3
| | | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3
| | | | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | +--- io.ktor:ktor-server-host-common:1.3.1
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61 -> 1.2.71 (*)
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61 -> 1.2.71 (*)
| | | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.3 (*)
| | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | | +--- io.ktor:ktor-server-core:1.3.1
| | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61 -> 1.2.71 (*)
| | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61 -> 1.2.71 (*)
| | | | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.3 (*)
| | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | | | +--- io.ktor:ktor-utils-jvm:1.3.1
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61 -> 1.2.71 (*)
| | | | | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | | | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3
| | | | | | | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| | | | | | \--- io.ktor:ktor-io-jvm:1.3.1
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | | | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | | | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| | | | | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3 (*)
| | | | | +--- io.ktor:ktor-http-jvm:1.3.1
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61 -> 1.2.71 (*)
| | | | | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | | | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3 (*)
| | | | | | \--- io.ktor:ktor-utils-jvm:1.3.1 (*)
| | | | | +--- com.typesafe:config:1.3.1
| | | | | \--- org.jetbrains.kotlin:kotlin-reflect:1.3.61 -> 1.2.71
| | | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.71 (*)
| | | | \--- io.ktor:ktor-http-cio-jvm:1.3.1
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | | +--- io.ktor:ktor-network:1.3.1
| | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | | | \--- io.ktor:ktor-utils-jvm:1.3.1 (*)
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3 (*)
| | | | \--- io.ktor:ktor-http-jvm:1.3.1 (*)
| | | +--- io.netty:netty-codec-http2:4.1.44.Final -> 4.1.31.Final
| | | | +--- io.netty:netty-codec-http:4.1.31.Final
| | | | | \--- io.netty:netty-codec:4.1.31.Final
| | | | | \--- io.netty:netty-transport:4.1.31.Final
| | | | | +--- io.netty:netty-buffer:4.1.31.Final
| | | | | | \--- io.netty:netty-common:4.1.31.Final
| | | | | \--- io.netty:netty-resolver:4.1.31.Final
| | | | | \--- io.netty:netty-common:4.1.31.Final
| | | | \--- io.netty:netty-handler:4.1.31.Final
| | | | +--- io.netty:netty-buffer:4.1.31.Final (*)
| | | | +--- io.netty:netty-transport:4.1.31.Final (*)
| | | | \--- io.netty:netty-codec:4.1.31.Final (*)
| | | +--- org.eclipse.jetty.alpn:alpn-api:1.1.3.v20160715
| | | +--- io.netty:netty-transport-native-kqueue:4.1.44.Final -> 4.1.31.Final
| | | | +--- io.netty:netty-common:4.1.31.Final
| | | | +--- io.netty:netty-buffer:4.1.31.Final (*)
| | | | +--- io.netty:netty-transport-native-unix-common:4.1.31.Final
| | | | | +--- io.netty:netty-common:4.1.31.Final
| | | | | \--- io.netty:netty-transport:4.1.31.Final (*)
| | | | \--- io.netty:netty-transport:4.1.31.Final (*)
| | | \--- io.netty:netty-transport-native-epoll:4.1.44.Final -> 4.1.31.Final
| | | +--- io.netty:netty-common:4.1.31.Final
| | | +--- io.netty:netty-buffer:4.1.31.Final (*)
| | | +--- io.netty:netty-transport-native-unix-common:4.1.31.Final (*)
| | | \--- io.netty:netty-transport:4.1.31.Final (*)
| | +--- io.ktor:ktor-network-tls-certificates:1.3.1
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61 -> 1.2.71 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61 -> 1.2.71 (*)
| | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.3 (*)
| | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | \--- io.ktor:ktor-network-tls:1.3.1
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61 -> 1.2.71 (*)
| | | +--- org.jetbrains.kotlinx:atomicfu:0.14.1 (*)
| | | +--- org.slf4j:slf4j-api:1.7.26 -> 1.7.25
| | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3 (*)
| | | +--- io.ktor:ktor-network:1.3.1 (*)
| | | \--- io.ktor:ktor-http-cio-jvm:1.3.1 (*)
| | +--- com.googlecode.java-diff-utils:diffutils:1.3.0
| | +--- dk.brics.automaton:automaton:1.11-8
| | +--- org.apache.httpcomponents:httpclient:4.5.5 -> 4.5.6
| | | +--- org.apache.httpcomponents:httpcore:4.4.10
| | | +--- commons-logging:commons-logging:1.2
| | | \--- commons-codec:commons-codec:1.10 -> 1.11
| | +--- org.json:json:20160212
| | +--- io.netty:netty-handler:4.1.44.Final -> 4.1.31.Final (*)
| | +--- org.apache.httpcomponents:httpmime:4.5.5 -> 4.5.6
| | | \--- org.apache.httpcomponents:httpclient:4.5.6 (*)
| | +--- org.apache.httpcomponents:fluent-hc:4.5.5 -> 4.5.6
| | | +--- org.apache.httpcomponents:httpclient:4.5.6 (*)
| | | \--- commons-logging:commons-logging:1.2
| | +--- au.com.dius.pact.core:model:4.1.7
| | | +--- org.slf4j:slf4j-api:1.7.28 -> 1.7.25
| | | +--- org.apache.tika:tika-core:1.24.1
| | | +--- com.github.zafarkhaja:java-semver:0.9.0
| | | +--- org.apache.commons:commons-collections4:4.1
| | | +--- com.github.mifmif:generex:1.0.2
| | | | \--- dk.brics.automaton:automaton:1.11-8
| | | +--- javax.mail:mail:1.5.0-b01
| | | | \--- javax.activation:activation:1.1
| | | +--- org.jetbrains.kotlin:kotlin-reflect:1.3.72 -> 1.2.71 (*)
| | | +--- au.com.dius.pact.core:support:4.1.7
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72 -> 1.2.71 (*)
| | | | +--- org.jetbrains.kotlin:kotlin-reflect:1.3.72 -> 1.2.71 (*)
| | | | +--- org.apache.commons:commons-lang3:3.4 -> 3.8.1
| | | | +--- com.google.code.findbugs:jsr305:3.0.2
| | | | +--- org.antlr:antlr4:4.7.2
| | | | | +--- org.antlr:antlr4-runtime:4.7.2
| | | | | +--- org.antlr:antlr-runtime:3.5.2
| | | | | +--- org.antlr:ST4:4.1
| | | | | | \--- org.antlr:antlr-runtime:3.5.2
| | | | | +--- org.abego.treelayout:org.abego.treelayout.core:1.0.3
| | | | | +--- org.glassfish:javax.json:1.0.4
| | | | | \--- com.ibm.icu:icu4j:61.1
| | | | +--- io.github.microutils:kotlin-logging:1.6.26
| | | | | +--- io.github.microutils:kotlin-logging-common:1.6.26
| | | | | \--- org.slf4j:slf4j-api:1.7.25
| | | | +--- org.apache.httpcomponents:httpclient:4.5.5 -> 4.5.6 (*)
| | | | \--- com.michael-bull.kotlin-result:kotlin-result:1.1.6
| | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -> 1.2.71 (*)
| | | \--- au.com.dius.pact.core:pactbroker:4.1.7
| | | +--- org.slf4j:slf4j-api:1.7.28 -> 1.7.25
| | | +--- org.apache.commons:commons-lang3:3.4 -> 3.8.1
| | | +--- com.google.guava:guava:18.0 -> 20.0
| | | +--- io.github.microutils:kotlin-logging:1.6.26 (*)
| | | +--- au.com.dius.pact.core:support:4.1.7 (*)
| | | \--- com.michael-bull.kotlin-result:kotlin-result:1.1.6 (*)
| | \--- au.com.dius.pact.core:matchers:4.1.7
| | +--- xerces:xercesImpl:2.12.0
| | | \--- xml-apis:xml-apis:1.4.01
| | +--- org.slf4j:slf4j-api:1.7.28 -> 1.7.25
| | +--- org.atteo:evo-inflector:1.2.2
| | +--- com.github.ajalt:mordant:1.2.1
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.21 -> 1.2.71 (*)
| | | \--- com.github.ajalt:colormath:1.2.0
| | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.51 -> 1.2.71 (*)
| | +--- org.apache.commons:commons-lang3:3.4 -> 3.8.1
| | +--- com.googlecode.java-diff-utils:diffutils:1.3.0
| | +--- au.com.dius.pact.core:model:4.1.7 (*)
| | \--- au.com.dius.pact.core:support:4.1.7 (*)
| +--- junit:junit:4.12 (*)
| +--- org.json:json:20160212
| +--- org.apache.commons:commons-lang3:3.4 -> 3.8.1
| \--- com.google.guava:guava:18.0 -> 20.0
I can't find the source of Kotlin 1.2.71 anywhere else in my dependency tree.
I added a short workaround on my main build.gradle
:
testCompile 'org.jetbrains.kotlin:kotlin-stdlib:1.3.72'
@makobernal I'm wondering if the spring boot plugin is causing this issue? The spring boot plugin can set the versions of the spring boot jars, and I wonder if it is modifying the project dependencies.
Hi. I just upgraded one of my Spring-Boot examples to Pact 4 and now the consumer tests fail in a strange way. I get
I can debug the code down to MockHttpServer line 227
val bodyContents = exchange.requestBody.readBytes()
. When I evaluate the expression it returns an empty byte array what is fine in a get call. But when stepping through the code the debugger (IntelliJ) just disappears on that line without catching any exception and the execution continues with the error in the log.I put the example on GitHub: https://github.com/scheuchzer/cdc-demo-2019-10.git The test consumer project is in the folder weather.
I noticed it is working fine with Java 8 until 3.6.13. Version 3.6.14 throws
with Java 8. After upgrade to Java 11 the same error occurs as with pact 4.0.0 is thrown btw. 3.6.13 is working fine with Java 11