Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VerifyError Illegal use of nonvirtual function call on Lambda expression in Java 8

Tags:

java

lambda

maven

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) {
            }
        });
    }
}

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

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.

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

like image 765
wsams Avatar asked Feb 06 '15 21:02

wsams


2 Answers

The reason could be that the interface is replaced by a version which was compiled on java 8 and rest of the code is on lower version say java 5. There is bug opened for this https://bugs.openjdk.java.net/browse/JDK-8004967

However, I don't think this is the case here since you are using java8 features in ExampleItemWriter and you have to compile it on java8. So there is no question of inconsistent targets. You can still consider rebuilding your entire project on java8.

like image 184
Parikshit Avatar answered Nov 16 '22 05:11

Parikshit


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.

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

like image 29
Bruno Avatar answered Nov 16 '22 06:11

Bruno