OkHttp: NoSuchMethodError copyInto in TlsUtil - kotlin

Running instrumentation tests with RESTMock we are getting this error
java.lang.NoSuchMethodError: No static method copyInto$default([Ljava/lang/Object;[Ljava/lang/Object;IIIILjava/lang/Object;)[Ljava/lang/Object; in class Lkotlin/collections/ArraysKt; or its super classes (declaration of 'kotlin.collections.ArraysKt' appears in /data/app/com.example.debug-1/base.apk)
FATAL EXCEPTION: pool-6-thread-1
Process: com.example.debug, PID: 6606
java.lang.NoSuchMethodError: No static method copyInto$default([Ljava/lang/Object;[Ljava/lang/Object;IIIILjava/lang/Object;)[Ljava/lang/Object; in class Lkotlin/collections/ArraysKt; or its super classes (declaration of 'kotlin.collections.ArraysKt' appears in /data/app/com.example.debug-1/base.apk)
at okhttp3.tls.internal.TlsUtil.newKeyManager(TlsUtil.kt:84)
at okhttp3.tls.HandshakeCertificates$Builder.build(HandshakeCertificates.kt:144)
at io.appflate.restmock.SslUtils.localhost(SslUtils.java:49)
at io.appflate.restmock.RESTMockServer.setUpHttps(RESTMockServer.java:91)
at io.appflate.restmock.RESTMockServer.init(RESTMockServer.java:74)
at io.appflate.restmock.RESTMockServerStarter$1.run(RESTMockServerStarter.java:56)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
This is the line in question in OkHttp
IIUC, Kotlin can treat a varargs as a Kotlin Array and then call extensions functions like copyInto
We're on OkHttp 4.0.1, Kotlin 1.3.40, R8 1.5.41
Our test apk correctly contains copyInto method so I don't think it's a proguard/R8 issue:
I'm at a loss as to what to test next. I asked on OkHttp's github issuse page and they suggested I post here link
Update: still happening on OkHttp 4.1.0. Also I realized that it can't be an R8 issue since R8 doesn't remove code from test apk.

I had a same issue , then added the mentioning lib to my project. It solved my problem:
maven :
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.3.70</version>
</dependency>
or
'org.jetbrains.kotlin:kotlin-stdlib:1.3.70'

I got the same issue when I was using okhttp3.mockwebserver.MockWebServer with https enabled with a server certificate from okhttp-tls.
In my case, the problem was that by just importing the com.squareup.okhttp3:okhttp-tls:4.2.0 dependency, org.jetbrains.kotlin:kotlin-stdlib was being resolved to version 1.2.71.
Given the copyInto method was introduced starting kotlin 1.3 it was failing with the same error you have.
I fixed it by adding explicitly the kotlin version in my gradle.build file:
testRuntime 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'

I got the same issue, but I'm developing a multi-module java project. It was useful that add a dependency for kotlin-stdlib in pom.xml that belongs to this module while unit testing...
When I boot this whole project, this issue came out agnain. Finally, I find this dependency need to be in the whole project's pom.xml, I mean the pom.xml in the project's root dir.

Related

Problems in IntelliJ since version 2022.1 / java.lang.NoClassDefFoundError

As of today, when I try to run some of my programs in IntelliJ today, this message was shown:
Executing pre-compile tasks...
Loading Ant configuration...
Running Ant tasks...
Running 'before' tasks
Checking sources
Finished, saving caches…
Module 'Listen' production: java.lang.NoClassDefFoundError: com/intellij/DynamicBundle
Executing post-compile tasks...
Loading Ant configuration...
Running Ant tasks...
Synchronizing output directories...
13.04.22, 14:54 - Build completed with 1 error and 0 warnings in 4 sec, 39 ms
This line is printed in red: Module 'Listen' production: java.lang.NoClassDefFoundError: com/intellij/DynamicBundle
I don't really have too much of an idea where I should look for the problem.
It seems to not have anything to do with the project itself. I already created a new Project and created a Hello World-program, which resulted in the same error.
Remarkably, yesterday my IntelliJ IDEA version was updated to version 2022.1.
Runtime version: 11.0.14.1+1-b2043.25 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
I have no idea either whether it has anything to do with the new version either.
I maintain another Project, which uses Scala language. That one is messed up even more:
Cannot process toolwindow sbt
java.lang.AbstractMethodError: Missing implementation of resolved method 'abstract com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings getSettings(com.intellij.openapi.project.Project)' of abstract class com.intellij.openapi.externalSystem.service.task.ui.AbstractExternalSystemToolWindowFactory.
at com.intellij.openapi.externalSystem.service.task.ui.AbstractExternalSystemToolWindowFactory.shouldBeAvailable(AbstractExternalSystemToolWindowFactory.java:35)
at com.intellij.toolWindow.ToolWindowSetInitializerKt.beanToTask(ToolWindowSetInitializer.kt:262)
at com.intellij.toolWindow.ToolWindowSetInitializerKt.beanToTask(ToolWindowSetInitializer.kt:248)
at com.intellij.toolWindow.ToolWindowSetInitializerKt.access$beanToTask(ToolWindowSetInitializer.kt:1)
at com.intellij.toolWindow.ToolWindowSetInitializerKt$computeToolWindowBeans$1.accept(ToolWindowSetInitializer.kt:278)
at com.intellij.toolWindow.ToolWindowSetInitializerKt$computeToolWindowBeans$1.accept(ToolWindowSetInitializer.kt)
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processWithPluginDescriptor(ExtensionPointImpl.java:301)
at com.intellij.toolWindow.ToolWindowSetInitializerKt.computeToolWindowBeans(ToolWindowSetInitializer.kt:274)
at com.intellij.toolWindow.ToolWindowSetInitializer$1.get(ToolWindowSetInitializer.kt:101)
at com.intellij.toolWindow.ToolWindowSetInitializer$1.get(ToolWindowSetInitializer.kt:83)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
at java.base/java.lang.Thread.run(Thread.java:829)
Any advice?
Best
Stapelüberläufer
I had the same problem after upgrading to Intellij 2022.1
For me, the fix came from Gen's answer. I also had an old Scala plugin, and just removed it as I'm not using it anymore.
If you are looking to upgrade it, go to File -> Settings -> Plugins. From there just hit Upgrade for the plugins you want. After that restart the IDE.
I found that Scala plugin was not updated and updating it to at least version 2022.1.13 fixed it for me.
I upgraded to Intellij 2022.1 and encountered this issue when trying to sync the old gradles projects that used to work for me :
Caused by: java.lang.NoClassDefFoundError: org/gradle/internal/impldep/com/google/common/collect/Lists
Cleaning the caches folder's content (Gradle_HOME/caches) resolved this issue for me
Make sure to also check that the SDK is correctly configured for your project (Java 17 by default) and the Gradle home is well specified in the Settings>Gradle section.
For info, I'm using Java 8 and Gradle 5.5.1 (yes I know :))
Just upgrade the Scala Plugin and its done!
visiting
scala plugin's page
and install it from there worked for me on ultimate version 2022.2.3

module can't find package com.google.gson.stream

a project i'm working with has a dependency on kotlin.jvm.internal.Intrinsics. so i added kotlin-gradle-plugin-1.5.0.jar. now i'm getting an error that it can't find gson.streams. any idea what this is all about?
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: E:\jars\kotlin-gradle-plugin-1.5.0.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Package com.google.gson.stream not found in module
i already have gson-2.8,6.jar in my classpath.
The Jar kotlin-gradle-plugin version 1.5.0 seems to have runtime dependency with com.google.code.gson » gson
you can see that in the Runtime Dependencies section from here
In order to rectify this, you have to add it as a plugin
like below
plugins {
id 'org.jetbrains.kotlin.<...>' version '1.5.0'
}
This is the recommended way from here

Kapt not processing micronaut-predator-processor

I am trying to use the new Predator JPA/JDBC library from Micronaut.
I wish to use the JDBC integration rather than JPA.
I am having a couple of issues however, the documentation says to include:
annotationProcessor 'io.micronaut.data:micronaut-predator-processor:1.0.0.BUILD-SNAPSHOT'
Which I have done so, but the kapt section of the build fails with the following error:
Caused by: java.lang.NoSuchMethodError: io.micronaut.core.annotation.AnnotationMetadata.enumValue(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/Class;)Ljava/util/Optional;
I am using micronaut 1.1.4 on JVM 12.0.1
If I replace kapt with annotationProcessor, the build completes fine, however I get a runtime issue:
Caused by: java.lang.ClassNotFoundException: io.micronaut.data.exceptions.DataAccessException
Which is odd as I seem to be able to use kapt/annotationProcessor interchangeable for micronaut security.
I faced the same problem when running tests from Intellij Idea. But they passed when run through gradle.
If you are using Intellij Idea and facing this issue, try following options in the sequence:
Invalidate Idea cache and restart
Enable Annotation Processing
Delegate IDE build/run actions to gradle. This setting had got reset to Idea when I upgraded my Intellij version.
I can get this to work for the micronaut 1.2.0 RC2 by updating the BOM entry:
dependencyManagement {
imports {
mavenBom 'io.micronaut:micronaut-bom:1.2.0.RC2'
}
}
This seems to allow all the annotation processing etc to work correctly.

Exception while running Seedstack Application

I have used seedstack dependecies for Hibernate and JPA to create DAO services that performs crud operations on Database.
I am trying to Launch this Seedstack application module through Java application Launcher in eclipse, by SeedMain class.
In pom.xml - dependecy for undertow is given.
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web-undertow</artifactId>
</dependency>
When executing the SeedMain class, I am getting the below error snakeyaml error:-
Exception in thread "main" java.lang.NoSuchMethodError: org.yaml.snakeyaml.DumperOptions.setSplitLines(Z)V
at com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.buildDumperOptions(YAMLGenerator.java:259)
at com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.<init>(YAMLGenerator.java:232)
at com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createGenerator(YAMLFactory.java:447)
at com.fasterxml.jackson.dataformat.yaml.YAMLFactory.createGenerator(YAMLFactory.java:397)
at org.seedstack.seed.core.internal.diagnostic.DefaultDiagnosticReporter.writeDiagnosticReport(DefaultDiagnosticReporter.java:75)
at org.seedstack.seed.core.internal.diagnostic.DefaultDiagnosticReporter.writeDiagnosticReport(DefaultDiagnosticReporter.java:67)
at org.seedstack.seed.core.internal.diagnostic.DiagnosticManagerImpl.dumpDiagnosticReport(DiagnosticManagerImpl.java:70)
at org.seedstack.seed.core.SeedMain.handleException(SeedMain.java:68)
at org.seedstack.seed.core.SeedMain.main(SeedMain.java:61)
As per my understanding the Error is due to some version inconsistency for snakeyaml, But for Seedstack as the versions for dependecies are resolved by seedstack-bom dependecy, so where exactly should I do the changes to resolve the error.
Thanks in Advance!
From reading the stacktrace, it seems that you have some error on startup which is handled by the handleException() method. This method then tries to write a YAML diagnostic report but ultimately fails due to the snakeyaml version issue you mentioned.
You should do two things:
Fix the snakeyaml dependency issue by looking into the dependency tree. This kind of problem is often caused by some library that makes Maven choose an older version. SeedStack needs at least jackson-dataformat-yaml version 2.9.4 which in turn needs at least snakeyaml 1.18.
Fix the other error by looking at the full stacktrace. When a diagnostic report cannot be written, the original exception is still printed on the console (on stderr).

IntelliJ Idea groovy.lang.GroovyRuntimeException: Conflicting module versions

My maven builds are fine and able to run groovy from cli. However if I try to run my groovy class inside IntelliJ Idea (version 15 community edition), its gives me below error.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:61)
at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
at groovy.lang.Closure.<init>(Closure.java:219)
at groovy.lang.Closure.<init>(Closure.java:236)
at groovy.lang.Closure$1.<init>(Closure.java:203)
at groovy.lang.Closure.<clinit>(Closure.java:203)
at filter.App.<clinit>(App.groovy)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.3.9 and you are trying to load version 2.4.5
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$DefaultModuleListener.onModule(MetaClassRegistryImpl.java:509)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromProperties(ExtensionModuleScanner.java:77)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromMetaInf(ExtensionModuleScanner.java:71)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModules(ExtensionModuleScanner.java:53)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:110)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:71)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:33)
... 10 more
Not sure how to get rid of this.
This is my pom dependency.
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.5</version>
</dependency>
And I am using spring boot.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath></relativePath>
</parent>
This is my groovy version installed in system.
Groovy Version: 2.4.5 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Linux
Please let me know if someone knows about this.
you have to delete groovy lib from project settings.
shift+alt+ctrl + s, global libraries - delete groovy. And when trying to run applictaion / test you should have point to groovy from maven dependencies.
#SuperAndrew's suggestion wasn't my situation -- I didn't have Groovy registered under Global Libraries under my Project Structure. But I did find this StackExchange solution resolved my issue. Add this code to your build.gradle file.
configurations.all {
resolutionStrategy {
force 'org.codehaus.groovy:groovy-all:2.4.4'
}
}
I was seeing this in a recent project after I upgraded Gradle to 7.+
The reason this was causing a problem for me was that Gradle 7.+ is now using Groovy 3.+ and as such various other plugins needed to be upgraded (e.g. spock-core).
It was this incompatibility of various dependencies that were causing this and once I updated all of them this issue went away.