我正试图将我的代码转换为lambda版本,我得到java.lang。ArrayIndexOutOfBoundsException: 18当我在构建代码时出现异常。
工作代码:
private void run(){
Producer<String, String> producer = (Producer<String, String>) new KafkaProducer();
producer.send(null, new Callback() {
public void onCompletion(RecordMetadata metadata, Exception e) { }
});
}
下面的代码给出了错误:
private void run(){
Producer<String, String> producer = (Producer<String, String>) new KafkaProducer();
producer.send(null, (metadata,e) -> { });
}
这是错误信息:
java.lang.ArrayIndexOutOfBoundsException: 18
at aQute.lib.osgi.Clazz.parseClassFile(Clazz.java:412)
at aQute.lib.osgi.Clazz.parseClassFile(Clazz.java:333)
at aQute.lib.osgi.Clazz.parseClassFileWithCollector(Clazz.java:323)
at aQute.lib.osgi.Clazz.parseClassFile(Clazz.java:313)
at aQute.lib.osgi.Analyzer.analyzeJar(Analyzer.java:1646)
at aQute.lib.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:1534)
at aQute.lib.osgi.Analyzer.analyze(Analyzer.java:115)
at aQute.lib.osgi.Builder.analyze(Builder.java:296)
at aQute.lib.osgi.Analyzer.calcManifest(Analyzer.java:292)
at aQute.lib.osgi.Builder.build(Builder.java:68)
at org.apache.felix.bundleplugin.BundlePlugin.buildOSGiBundle(BundlePlugin.java:375)
at org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:270)
at org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:224)
at org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:215)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
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.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR] Error building bundle com.wso2telco:logging-extension:bundle:3.0.0 : Exception: 18
[ERROR] Error building bundle com.wso2telco:logging-extension:bundle:3.0.0 : Invalid class file: MessageSender$KafkaDataPublisher.class
[ERROR] Error(s) found in bundle configuration
请注意,为了简化,大部分代码被删除了。
简化后的完整代码:(这是工作代码)
public class MessageSender {
ExecutorService executorService = null;
public MessageSender(ExecutorService executorService) {
this.executorService = executorService;
}
public void sendMessage(String transactionLog) {
Runnable worker = new KafkaDataPublisher();
executorService.execute(worker);
}
public static class KafkaDataPublisher implements Runnable {
@Override
public void run() {
Producer<String, String> producer = (Producer<String, String>) new KafkaProducer();
producer.send(null, new Callback() {
public void onCompletion(RecordMetadata metadata, Exception e) {}
});
}
}
}
版本:Java 8
你试过吗?
private void run(){
Producer<String, String> producer = (Producer<String, String>) new KafkaProducer();
producer.send(null, (RecordMetadata metadata, Exception e) -> { });
}