VerifyError在Java 8中非法使用Lambda表达式进行非虚拟函数调用 [英] VerifyError Illegal use of nonvirtual function call on Lambda expression in Java 8

查看:56
本文介绍了VerifyError在Java 8中非法使用Lambda表达式进行非虚拟函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个最近引入了lambda表达式的项目.一个例子就是这样.

I'm working on a project that has recently been introducing lambda expressions. One example goes like this.

public class ExampleItemWriter implements ItemWriter<MyItem> {
    public void write(List<? extends MyItem> list) throws RepositoryException {
        list.stream().forEach((item)->{
            if (item == null) {
            }
        });
    }
}

我不相信 forEach()中的详细信息与问题有关,但如果可以,则可以发布.整个代码中还有其他类似的表达式会抛出相同的异常.

I don't believe the details inside the forEach() are relevant to the problem, but if they are I can post. There are a few other expressions like this throughout the code that throw the same exception.

java.lang.BootstrapMethodError: call site initialization exception
        at java.lang.invoke.CallSite.makeSite(CallSite.java:328)
        at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:296)
        at com.example.repository.batch.ExampleItemWriter.write(ExampleItemWriter.java:83)
        at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
        at com.sun.proxy.$Proxy93.write(Unknown Source)
        at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
        at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
        at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor$3.doWithRetry(FaultTolerantChunkProcessor.java:329)
        at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:255)
        at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:188)
        at org.springframework.batch.core.step.item.BatchRetryTemplate.execute(BatchRetryTemplate.java:217)
        at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor.write(FaultTolerantChunkProcessor.java:422)
        at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199)
        at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:395)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
        at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:267)
        at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)
        at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)
        at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
        at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
        at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253)
        at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:137)
        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:152)
        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:131)
        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)
        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134)
        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
        at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127)
        at com.example.repository.batch.RunScheduler.run(RunScheduler.java:69)
        at com.example.repository.batch.messaging.listener.SourceJobRunner.runSourceJob(SourceJobRunner.java:139)
        at com.example.repository.batch.messaging.listener.SourceJobRunner.onMessage(SourceJobRunner.java:94)
        at org.springframework.jms.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:214)
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:660)
        at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:620)
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:591)
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:308)
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:246)
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1142)
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1134)
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1031)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.VerifyError: (class: com/example/repository/batch/ExampleItemWriter$$Lambda$57, method: accept signature: (Ljava/lang/Object;)V) Illegal use of nonvirtual function call
        at sun.misc.Unsafe.defineAnonymousClass(Native Method)
        at java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:324)
        at java.lang.invoke.InnerClassLambdaMetafactory.buildCallSite(InnerClassLambdaMetafactory.java:194)
        at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:304)
        at java.lang.invoke.CallSite.makeSite(CallSite.java:289)
        ... 54 more

我们有几个运行相同代码的不同环境,只有其中一些抛出此异常.我花了很多时间解决这个问题,最后将其发布在这里以征求意见.这些环境看起来具有相同的jdk 1.8.0_31,我们正在使用maven-compiler-plugin 3.2.

We have a few different environments running the same code and only some of them throw this exception. I've spent many hours on this problem and finally posting it here for ideas. The environments look like they have the same jdk 1.8.0_31 and we're using the maven-compiler-plugin 3.2.

关于我们可能会看到什么的任何提示?我没主意了.谢谢,/w

Any tips on where we might look? I'm out of ideas. Thanks, /w

推荐答案

我将您的write方法复制到另一个类中,用String替换MyItem并使用常规的Exception.因此,这对于字符串列表来说很好用.

I copied your write method into another class, replacing MyItem by String and using a regular Exception. So, this worked fine for a list of strings.

因此,我认为这与您的forEach()内容有关,或者-上面提到的-与版本冲突有关.

So I assume this either has to do with your content of forEach(), or - what was mentioned above - with a version conflict.

这篇关于VerifyError在Java 8中非法使用Lambda表达式进行非虚拟函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆