java.lang.NoSuchFieldException error from jacoco - java

I am trying to run the tests of the kotlin code provided from here : https://github.com/ligi/ipfs-api-kotlin with gradlew
I got the error listed below.
Could someone tell me what this error means ?
> Task :test FAILED
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/lang/UnknownError could not be instrumented.
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_c13123e.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_c13123e.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.base/java.lang.Class.getField(Class.java:1999)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at line: 422

I was missing the following from my build.gradle:
jacoco {
toolVersion = "0.8.6"
}
While obvious, build.gradle can inherit properties from other gradle files and for reasons I can't figure out, jacoco was passing through in to one subproject but not to another.

Ensure you are using JDK-11,
if using maven, ensure;
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Ensure you are using latest jacoco.
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>

Fixed this error changing Java SDK in my project from 14 to 11 and my tests started working fine.
Solution:
IntellijIDEA: File > Project Structure > Project Tab > SDK adopt-opendjdk-11 (in my case for Ubuntu).
Oh! Make sure Gradle Settings are also using the same JVM!
Hope that helps someone out there.

The issue comes from the Java version which needs not to be too recent.
sdk install java 19.3.0.2.r8-grl
makes things ok.

After followed below steps it's working fine for me.
In Eclipse,Go to Window--Preferences--java.Right-click on installed JRE. There add an installed JDK path & remove others.

I had similar issue when I upgraded my jdk1.8 to openjdk11 but it was solved by updating the toolVersion = "0.8.6" (used toolVersion = "0.8.1" with jdk1.8)

Fix in my case was to download and install Java 8 (jdk1.8.0_301) and set it in Project Settings

Related

Solving groovy module version conflict

How to solve groovy module (groovy-xml) version conflict?
The version 2.4.12 is what my currently project depends on, however, groovysh somehow preload a higher version:
$ groovysh
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:111)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:129)
Caused by: java.lang.ExceptionInInitializerError
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:88)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:82)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:277)
at org.apache.groovy.groovysh.Main.main(Main.groovy:74)
... 6 more
Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-xml is loaded in version 3.0.7 and you are trying to load version 2.4.12
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$DefaultModuleListener.onModule(MetaClassRegistryImpl.java:510)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromProperties(ExtensionModuleScanner.java:87)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromMetaInf(ExtensionModuleScanner.java:81)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModulesFrom(ExtensionModuleScanner.java:63)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModules(ExtensionModuleScanner.java:55)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:125)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:86)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:37)
... 12 more
More info, this is Mac, and groovy is installed by brew install groovy, and there is no GROOVY related environment variables created:
$ env | grep GROOVY | wc
0 0 0
I suggest to use skdman to manage your Groovy installations, this will create the GROVY_HOME env variable for you, the other way is to find the location of your groovy installation and create a GROVY_HOME env pointing to bin location inside Groovy folder.
Pay attention to the fact that when you install groovy, the installer creates an environment variable called "GROOVY_HOME". To resolve your conflict you should remove the 3.0.7 as the default version in your environment.
EDIT ( see OP comment )
In case the above solution doesn't work for you, here is another way:
Edit the project's build.gradle to force gradle load your suitable version of groovy :
configurations.all { resolutionStrategy { force 'org.codehaus.groovy:groovy-all: 2.4.12' } }

java.lang.NoClassDefFoundError: org/yaml/snakeyaml/constructor/BaseConstructor

When I am trying to run flutter app in simulator i get error:
java.lang.NoClassDefFoundError: org/yaml/snakeyaml/constructor/BaseConstructor
at org.testng.internal.YamlParser.parse(YamlParser.java:16)
at org.testng.internal.YamlParser.parse(YamlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:168)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:46)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.ClassNotFoundException: org.yaml.snakeyaml.constructor.BaseConstructor
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
Process finished with exit code -1
You are missing the JAR file for snakeyaml from the classpath. However, judging from the stacktrace, you are not running a flutter app at this point. It looks like that the exception is occurring in the testng launcher.
So I suspect that the problem is a version conflict between the versions of snakeyaml required by the test framework and something you are testing. Here is an example Q&A from a different context:
java.lang.NoClassDefFoundError: org/yaml
The work-around in that case was to exclude nestng's transitive snakeyaml dependency; see above link for the details. (You will most likely need to map from the Maven POM syntax to the equivalent Gradle syntax.)

Exception in thread "main" java.lang.reflect.InvocationTargetException while installing maven project

I'm trying to install maven project but facing an
exception: Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test
(default-test)
There are test failures.
When I looked at the .dump file I see this:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/lang/UnknownError could not be instrumented.
org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_c13123e.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_c13123e.PreMain.premain(PreMain.java:47)
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.base/java.lang.Class.getField(Class.java:1999)
org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at line: 422
I'm pretty sure there is no any problems in the code as it works well on other computers. Skipping tests is not an option because it is an integration-tests module
The answer below helped. For me it was a problem between Jacoco version and my JDK.
There are two options to solve this:
Make sure that there is an appropriate version for your JDK and upgrade jacoco
Use an older JDK
Just to add to the given answer. My issue was due to the fact that I was using Java 14. JaCoCo needed an older version. So I downloaded and installed JDK 1.8.0. Now in IntelliJ:
Go to project structure (top right)
Click on Project under Project Settings
Then select JDK 1.8

Unsupported major.minor version 52.0 - trying to look for Java 8, which is already set in Java_home and Path

I am trying to run my automation code built in cucumber framework by Jenkins job, in which environment variables are set by injecting via build setup. I am getting the following error.
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content
PATH=/data/java/jdk180152/bin:/data/build_tools/maven/apache-maven-3.5.2/bin:/data/build_tools/python/python-2.7.14/bin/:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:
M2_HOME=/data/build_tools/maven/apache-maven-3.5.2
JDK_HOME=/data/java/jdk180152
JAVA_HOME=/data/java/jdk180152
MAVEN_HOME=/data/build_tools/maven/apache-maven-3.5.2
[EnvInject] - Variables injected successfully.
Parsing POMs
Established TCP socket on 33831
[cafeAutomation] $ java -cp /data/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.12-alpha-1.jar:/data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven-3.5.2/boot/plexus-classworlds-2.5.2.jar:/data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven-3.5.2/conf/logging jenkins.maven3.agent.Maven35Main /data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven-3.5.2 /var/cache/jenkins/war/WEB-INF/lib/remoting-3.14.jar /data/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.12-alpha-1.jar /data/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.12-alpha-1.jar 33831
Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:133)
at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:64)
ERROR: ================================================================================
ERROR: Invalid project setup: Connection reset
ERROR: Processing failed due to a bug in the code. Please report this to the issue tracker (https://jenkins.io/redirect/report-an-issue).
java.lang.NullPointerException
at hudson.maven.AbstractMavenProcessFactory.newProcess(AbstractMavenProcessFactory.java:304)
at hudson.maven.ProcessCache.get(ProcessCache.java:236)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:804)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1724)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:421)
project=hudson.maven.MavenModuleSet#6b7062ed[smr-qa-maven]
project.getModules()=[hudson.maven.MavenModule#10ea4a41[smr-qa-maven/cafeAutomatin:cafeAutomation][smr-qa-maven/cafeAutomation:cafeAutomation][relativePath:WebApp/Automation Scripts/CAFE Automation Scripts/cafeAutomation]]
project.getRootModule()=hudson.maven.MavenModule#10ea4a41[smr-qa-maven/cafeAutomation:cafeAutomation][smr-qa-maven/cafeAutomation:cafeAutomation][relativePath:WebApp/Automation Scripts/CAFE Automation Scripts/cafeAutomation]
FATAL: null
Java version installed on the box - Java 8,
Maven - 3.5.2,
Jenkins version - 2.89.3
In my pom.xml file, I have mentioned the plugin as
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<executable>/data/java/jdk180152/bin/javac</executable>
</configuration>
</plugin>
Have also tried by adding the following to the pom file, but still the same error
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
I have run into the same problem. It was anoying because I was trying to build an existing project which was not changed since over one year. I always got following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at jenkins.maven3.agent.Maven33Main.main(Maven33Main.java:133)
at jenkins.maven3.agent.Maven33Main.main(Maven33Main.java:64)
ERROR: ================================================================================
ERROR: Invalid project setup: Connection reset
ERROR: [JENKINS-18403][JENKINS-28294] JDK 'JDK7' not supported to run Maven projects.
ERROR: Maven projects have to be launched with a Java version greater or equal to the minimum version required by the master.
ERROR: Use the Maven JDK Toolchains (plugin) to build your maven project with an older JDK.
ERROR: Retrying with slave Java and setting compile/test properties to point to /var/tomcat/java/jdk7/.
ERROR: ================================================================================
Some one from OPS team had updated jeikins version and that is the clue! I came around following site Maven jobs and Java versions compatibility. The problem is very well described on that site by one sentense:
Because java serialized classes are exchanged between Jenkins master
and Maven Jobs it is required that the JVM used to launch Maven is
superior or equal to the version of Java for which Jenkins Master is
built for.
I opened my Jenkins project and changed the "JDK" settings. After changing the java version (in my case to Java 8) everything was fine and my project was building successfully.
Well I don't know if this is a correct answer or a workaround. I didn't had permissions to go to Manage Jenkins. When the admin user set the JDK through Manage Jenkins option, everything worked fine.
I used to have a similar problem with Java 7 (hudson/remoting/Launcher : Unsupported major.minor version 52.0). I ended up configuring a Freestyle Job instead of a Maven Job in Jenkins. It solved my issue.
The sad answer is that you are trying to execute a modern class file on an old JVM. The JVM you are trying to use is not the one you are using when running you run the commands manually.
My guess is that the Jenkins user have another JVM on its path than the user you login as when you do your testing.
Run the same commands as the Jenkins user and you might find that it is another JVM being used.

java.lang.NoClassDefFoundError: Could not initialize class hudson.util.ProcessTree$UnixReflection

I am having this problem when trying to build my project with Jenkins:
java.lang.NoClassDefFoundError: Could not initialize class hudson.util.ProcessTree$UnixReflection.
java.lang.NoClassDefFoundError: Could not initialize class hudson.util.ProcessTree$UnixReflection
at hudson.util.ProcessTree$Unix.get(ProcessTree.java:506)
at hudson.util.ProcessTree.killAll(ProcessTree.java:144)
at hudson.Proc$LocalProc.destroy(Proc.java:380)
at hudson.Proc$LocalProc.join(Proc.java:353)
at hudson.tasks.CommandInterpreter.join(CommandInterpreter.java:155)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1728)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:405)
I have tried to downgrade from JAVA JDK 1.8 to 1.7 but still not resolving the problem.
This is a JavaScript project, the test are passing but build failed because of that error.
Could you help me?
We fixed it by reducing jenkins stdout/stderr output. Just redirect called commands' output to files and try again.
It is just a workaround until Jenkins team fix it but it works pretty well for us.

Categories