Caused by: java.lang.NoClassDefFoundError: com_atlassian_clover/TestNameSniffer - java

Getting below error on invoking TestNG unit test cases with clover profile enabled. Did not change any clover version. Not getting any clue why its happening.
Here is my libs details - clover-4.0.3, testng - 6.0.1, maven 3
Caused by: java.lang.NoClassDefFoundError: com_atlassian_clover/TestNameSniffer
at com.mds404.catalog.infrastructure.entity.ModelBase.<clinit>(ModelBase.java:27)
at sun.reflect.GeneratedSerializationConstructorAccessor1.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:111)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:51)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:52)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:41)
at org.mockito.Mockito.mock(Mockito.java:1014)
at org.mockito.Mockito.mock(Mockito.java:909)
at com.mds404.rest.v2.controller.BaseControllerTest.<init>(BaseControllerTest.java:107)
... 33 more
Caused by: java.lang.ClassNotFoundException: com_atlassian_clover.TestNameSniffer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:97)
... 46 more

The error
Caused by: java.lang.NoClassDefFoundError: com_atlassian_clover/TestNameSniffer
means that the Clover JAR (com.atlassian.clover:clover) is missing on the class path.
This is usually caused by two issues:
Missing com.atlassian.clover:clover dependency. Please note that the Clover Maven Plugin adds this dependency to the project automatically (during the build). However, in some cases, you have to add this dependency manually to other Maven plugins - usually to those which fork new JVM - for instance for in-container tests.
Build is running with Clover disabled but still failing on this error. This usually happens if you run the build with Clover enabled via 'clover:setup' and next install (or deploy) JARs created. When you run your build again, but this time with Clover disabled, the build can fetch these JARs from your ~/.m2 cache. As these JARs contain instrumented code and com.atlassian.clover:clover is missing, build will fail. To solve this problem, clean up your ~/.m2 cache and don't use "clover:setup" with "install" or "deploy".
Reference:
https://confluence.atlassian.com/cloverkb/noclassdeffounderror-com_atlassian_clover-coveragerecorder-317196439.html
Cheers
Marek

So finally what did help me here is adding another dependency of clover in dependencies tag. I already had this dependency as part of clover profile. But still I was getting above reported error.
After spending few hours when I added one more time same dependency next to all other libraries. As I was out of thoughts. And magically it did work.
Here is my updated pom.xml with both dependency copies -
...
<profile>
<id>clover</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>4.0.3</version>
<configuration>
<methodContexts>
<toStr>(.* )?public .*(toString).*</toStr>
<hashCode>(.* )?public .*(hashCode).*</hashCode>
<equals>(.* )?public boolean equals\(Object.*\).*</equals>
<privateConstructors>(.* )?private +[a-zA-Z0-9]+ *\(\).*</privateConstructors>
</methodContexts>
<contextFilters>toStr,hashCode,equals,privateConstructors</contextFilters>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.atlassian.clover</groupId>
<artifactId>clover</artifactId>
<version>4.0.3</version>
</dependency>
</dependencies>
</profile>
And then all other dependencies -
....
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>com.atlassian.clover</groupId>
<artifactId>clover</artifactId>
<version>4.0.3</version>
</dependency>
...

I stumbled across this error, that is, running my unit test I got
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.082 s <<< FAILURE! - in [...]
[ERROR] [...] Time elapsed: 0.017 s <<< ERROR!
java.lang.NoClassDefFoundError: com_atlassian_clover/TestNameSniffer
at [...]
Caused by: java.lang.ClassNotFoundException: com_atlassian_clover.TestNameSniffer
at [...]
First, let me say that this error really puzzled me, since I was sure that the same configuration of the project did not had this error before.
Here is what caused this error:
The project that exhibits the error references a dependency which I own or which I build and installed in my maven repository.
That dependency was mvn clean install-ed during a "Clover" run, that is, the version in .m2/repository had some clover code compiled into it.
Of course, this resulted in the other project pulling in some clover-instrumented code, without the required dependency.
The issue disappeared, once I have removed the dependency from my .m2/repository such that it was pulled from Maven central (which was clean and did not had the clover code).
Edit: Just saw that his was the second case in Mareks answer.

Related

When I am trying to run mvn dependency:tree , I am getting : java.lang.NoClassDefFoundError: org/sonatype/aether/version/VersionConstraint

I have no idea why this is happening. I tried deleting my m2 repository as well.
I tried with various versions of maven plugins(2.8) as well.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
</dependency>
Here is the complete stacktrace :
Error injecting: org.apache.maven.shared.dependency.graph.internal.Maven3DependencyGraphBuilder
java.lang.NoClassDefFoundError: org/sonatype/aether/version/VersionConstraint
at java.lang.Class.getDeclaredMethods0 (Native Method)
at java.lang.Class.privateGetDeclaredMethods (Class.java:2701)
at java.lang.Class.getDeclaredMethods (Class.java:1975)
at com.google.inject.spi.InjectionPoint.getDeclaredMethods (InjectionPoint.java:766)
at com.google.inject.spi.InjectionPoint.getInjectionPoints (InjectionPoint.java:683)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields (InjectionPoint.java:378)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies
(ConstructorBindingImpl.java:181)
Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.version.VersionConstraint
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
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 java.lang.Class.getDeclaredMethods0 (Native Method)
at java.lang.Class.privateGetDeclaredMethods (Class.java:2701)
at java.lang.Class.getDeclaredMethods (Class.java:1975)
at com.google.inject.spi.InjectionPoint.getDeclaredMethods (InjectionPoint.java:766)
at com.google.inject.spi.InjectionPoint.getInjectionPoints (InjectionPoint.java:683)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields (InjectionPoint.java:378)
You can solve by using an older version of the plugin as indicated by the official page recalled by the error log:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:tree
Update Maven version, at least to 3.0.x+ or 3.1.x+ see here
This error is caused by Maven 3.1-alpha-1 migration from Sonatype
Aether to Eclipse Aether (MNG-5354), which is an incompatible change
for some plugins.
Other report here claim to use Maven 3.3.0, so in any case, try with latest stable maven first (you can get it from here)
Side question: are you developing maven plugin? Usually you shouldn't declare dependencies on plugins in your pom.xml

Getting ClassNotFoundException SdkClientException in maven project

I am java/maven newbie and I am running into this weird issue and was hoping someone can shade some lights on it.
I have two maven project. Project A which is a dependency of class B. Project A in its pom.xml declare aws java sdk as its dependency:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.549</version>
</dependency>
Now Project B declare project A as its dependency and also declare aws-java-sdk-s3 with the exact same version as aws-java-sdk in project A:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.549</version>
</dependency>
However In my Intellij Dependency Analyzer I can see project B is using two version of s3 sdk 1.11.43 and 1.11.549. But Project A is using the correct version 1.11.549.
If I run project B inside my docker container it is throwing the following error:
... 41 more Caused by: java.lang.ClassNotFoundException:
com.amazonaws.SdkClientException at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedUR
LClassLoader.java:93) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 53 more
However when I remove the s3 sdk from dependency of project B the application come up successfully!
Can someone please explain to me or show me some pointers on how to debug this?
Also here is my intellij Analyzer

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module

new user here!
I know there's similar questions with answers to this, but I don't know how to apply them to my case, so sorry if it's repetitive!
So... I'm trying to make my first bot for Telegram and I've decided to use Java. I'm following this tutorial and copypasted the code from the two example classes (EchoBot and Main). The only thing I changed is the token with the token I got from the BotGodfather on Telegram.
I'm using Eclipse on Ubuntu 18.04.1 as IDE so I started by making a Java project and then configured it as a Maven project. This is the code of my pom.xml:
`
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>EchoBot</groupId>
<artifactId>EchoBot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>EchoBot</name>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
`
When I run the program I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module
at org.telegram.telegrambots.ApiContext.getInjector(ApiContext.java:46)
at org.telegram.telegrambots.ApiContext.getInstance(ApiContext.java:25)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.(TelegramLongPollingBot.java:17)
at pearlbot.EchoBot.(EchoBot.java:8)
at pearlbot.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Module
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 5 more
What could the problem be?
Keep in mind that I don't even know what Maven is, so if it's something related to it, you'll need to explain what's wrong as if you were talking to a child! ^^''
I got this error when i try to install testng for eclipse Version: 2019-12 (4.14.0) and run the program then i got this error. Finally i got fixed -
Eclipse IDE for Java Developers, Version: 2019-12 (4.14.0), Build id: 20191212-1212.
TestNG 7.1.0.r202001120626
Removing the TestNG library from the build path of the project containing the test and installing TestNG from menu Help / Install New Software did not work for me, I kept getting this error.
What worked for me was downloading guice-4.2.2.jar (from https://github.com/google/guice/wiki/Guice422), copying it into any folder, and adding it to the build path of the project as external JAR.
From Eclipse, Go to Help > Install software or You can install from market place as well (Help > Market Place). After installing TestNG from market place, it dint work, but installing the GUICE422.jar to the build path worked for me
So make sure after installing TestNG from market place, install the Guice422 Jar file as well link to install testng from eclipse market place
This worked for me --- Hope it helps

Nutch: NoClassDefFoundError: org/springframework/retry/RetryCallback

I am running the normal Nutch indexing, it used to work 2 days ago perfectly but today out of nowhere it just stopped working with the previous error. Following the stack error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/retry/RetryCallback
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.apache.nutch.plugin.Extension.getExtensionInstance(Extension.java:161)
at org.apache.nutch.indexer.IndexWriters.<init>(IndexWriters.java:55)
at org.apache.nutch.indexer.IndexingJob.index(IndexingJob.java:121)
at org.apache.nutch.indexer.IndexingJob.run(IndexingJob.java:228)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.nutch.indexer.IndexingJob.main(IndexingJob.java:238)
Caused by: java.lang.ClassNotFoundException: org.springframework.retry.RetryCallback
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 10 more
I ended up seeing that the error occurred at this exact piece of code :
Object object = extensionClazz.newInstance();
Another question on SO but with different project was able to fix the issue by adding the spring-framework-messaging dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
well i am using nutch version 1.12 with ivy for dependency management so in my config is the following:
<dependency org="org.springframework.retry" name="spring-retry" rev="1.2.0.RELEASE">
<exclude module="spring-beans"/>
<exclude module="spring-context"/>
<exclude module="spring-core"/>
<exclude module="spring-aop"/>
</dependency>
and even with adding the spring-messaging dependency it's still not working.
Any ideas?
These kind of errors might come when you have more than one version of same jar (same class) in your classpath, You can see the dependency tree by executing
<report conf="compile" /> for ivy projects
And
mvn dependency:tree for maven projects
Narrow down to the version that you want and you can exclude the other jar by explicitly excluding that jar from the module which is importing it .
No idea what went wrong but this was able to fix the problem
ant clean
ant runtime

IllegalStateException in Hibernate metamodel generation with maven

I'm using hibernate-jpamodelgen to generate the metamodel classes using maven.
When i run mvn clean package, it works fine without any problem. But if i run the mvn package second time (without clean), I'm getting the following exception :
An exception has occurred in the compiler (1.8.0_51). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.IllegalStateException: endPosTable already set
at com.sun.tools.javac.util.DiagnosticSource.setEndPosTable(DiagnosticSource.java:136)
at com.sun.tools.javac.util.Log.setEndPosTable(Log.java:350)
at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:667)
at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.<init>(JavacProcessingEnvironment.java:892)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.next(JavacProcessingEnvironment.java:921)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1187)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)
at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:825)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
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:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Environment:
JDK version : 1.8.0_51
Maven version : 3.3
Hibernate version : 4.3.7.Final
Snippet from my pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.7.Final</version>
<scope>provided</scope>
</dependency>
Found the Answer!...
It's a bug in 3.2 & 3.3 versions of maven-compiler-plugin.
When I run the 'mvn package' second time, the previously generated source directory is added to the source path before the generate-source phase and it causes this parser exception.
Switching back to the older version (<3.2) of maven-compiler-plugin fixes the issue.
Note that the incremental compilation is broken in 3.0 & 3.1 versions of maven-compiler-plugin. So, I prefer to switch the 2.5.1 version of maven-compiler-plugin.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</dependency>
Same issue faced with gradle build as well.
If you have previously metamodel classes available # source-generate(please check the build.gradle file to check the path where your model classes being generated), this issue will come when run gradle build.
Solution : Delete the existing model classes and run gradle build. It should workout.
This bug is fixed in the meantime. You should use maven compiler plugin 3.6 or higher:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
</dependency>
I have just found another cause of this error: an old version of the maven-processor-plugin (2.1.0 in my case). I got the 'endPosTable already set' even when running mvn clean package. Upgrading the maven-processor-plugin and hibernate-jpamodelgen to the latest versions helped.
I managed to solve this error (happening in CI/CD but was not an issue locally) by removing the maven-processor-plugin. My intelliJ still picks up references to the modelgen classes and only required import of the dependancy

Categories

Resources