我创建了JMH主页中指定的maven原型项目。 我得到“注释生成器抛出了异常.java.lang.NullPointerException” 当我做maven构建生成的项目时。 我的java文件是
public class MyBenchMark
// extends Benchmark
{
@GenerateMicroBenchmark
public void timeMyOperation(int reps) {
for (int i = 0; i < reps; i++) {
// ConcurrentHashMapTest.populateConcurrenctHashMap();
}
}
public static void main(String args[]) throws RunnerException {
MyBenchMark myBenchMark = new MyBenchMark();
// myBenchMark.timeMyOperation(50);
Options opt = new OptionsBuilder()
.include(".*" + MyBenchMark.class.getSimpleName() + ".*")
.forks(1)
.build();
new Runner(opt).run();
}
}
`。 我得到的例外是
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project perftest: Compilation failure
error: Annotation generator had thrown the exception. java.lang.NullPointerException
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
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:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
error: Annotation generator had thrown the exception. java.lang.NullPointerException
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:745)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:118)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 25 more
答案 0 :(得分:1)
int reps
是JMH的绊脚石。根据{{1}} Javadoc:
&#34;参数应为零或更多的国家承担类。有关确切的合同,请参阅州文档。&#34;从参数中删除GenerateMicroBenchmark
,它应该没问题。顺便说一句,你对你的基准测试所做的事情是值得怀疑的,请先阅读JMH samples。
错误信息应该更好,正在努力。