简体   繁体   English

Java 8 Lambda-运行时错误

[英]Java 8 lambda - runtime error

We have below code in our project and although it works fine but randomly we get class def not found error at runtime. 我们的项目中有以下代码,尽管可以正常工作,但在运行时会随机发现类def错误。 Our App servers are restarted on each Sunday so sometimes we get this error on any random server instance. 我们的App服务器在每个星期日重新启动,因此有时我们在任何随机服务器实例上都会收到此错误。 Server restart fix the problem but any clue as why the class loading breaks in between. 服务器重新启动解决了该问题,但没有任何线索说明类加载为何在两者之间中断。

I got somewhat similar error in this question and seems the issue is fixed in jdk 9 Transforming lambdas in Java 8 我在此问题中遇到了类似的错误,并且似乎该问题已在Java 8的 jdk 9 Transformation lambdas中修复。

But before I conclude can someone explain it is the same kind of error and why it happens occasionally. 但是在我得出结论之前,有人可以解释这是同一种错误,以及为什么偶尔会发生这种错误。

public boolean isAttachmentExpired(final Document_Attachment da) {
    return this.bcDocumentScreen.getValidator().getAttachmentsValidator().isAttachmentExpired(da);
}

public boolean isAttachmentWarningShown() {
    return CollectionUtils.isNotEmpty(getAttachments()) && getAttachments().stream().anyMatch(this::isAttachmentExpired);
}

public boolean isAttachmentExpired(final Document_Attachment da) {
        final Date today = DateHelper.today();
        return DateHelper.diffInYears(today, da.getUploaded()) >= 1;
    }

Error:- 错误:-

Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor1913.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
        at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
        at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:79)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.persistence.ManagedEntityInterceptor.aroundInvoke(ManagedEntityInterceptor.java:48)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
        at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:196)
        at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:114)
        at com.XXX.BcdAttachmentsSection_$$_javassist_seam_91.isAttachmentWarningShown(BcdAttachmentsSection_$$_javassist_seam_91.java)
        at sun.reflect.GeneratedMethodAccessor1912.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
        at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
        at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
        at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
        at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
        at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
        ... 122 more
Caused by: java.lang.NoClassDefFoundError: com/XXX/docsections/BcdAttachmentsSection$$Lambda$75
        at com.XXX.BcdAttachmentsSection$$Lambda$75/1736532374.get$Lambda(Unknown Source)
        at com.XXXX.isAttachmentWarningShown(BcdAttachmentsSection.java:51)
        ... 150 more

It's quite possible that the bug, you have linked does apply, if Instrumentation is involved. 如果涉及到检测,您链接的错误很可能确实适用。 Consider this bug, JDK-8027681, “Lambda serialization fails once reflection proxy generation kicks in” , that affected all Reflection operations that are performed more than 16 times (this is a configurable threshold), as the underlying implementation will optimize subsequent calls by generating an accessor class, consisting of bytecode that HotSpot can inline. 考虑此错误, JDK-8027681,“一旦启动反射代理生成,Lambda序列化就会失败” ,它影响了执行了16次以上的所有反射操作(这是可配置的阈值),因为基础实现将通过生成来优化后续调用一个访问器类,由HotSpot可以内联的字节码组成。 This bytecode failed to access the anonymous classes generated for lambda expressions in early version of Java 8. 此字节码无法访问Java 8早期版本中为lambda表达式生成的匿名类。

While this bug has been fixed, the described behavior of generating classes after a certain number of invocations still exists, so if an agent attempts to instrument these generated classes, it would fail due to the still existing Instrumentation bug and the dependency to the number of invocations is likely the reason why this only occurs occasionally. 尽管已修复此错误,但仍然存在上述描述的在一定数量的调用后生成类的行为,因此,如果代理尝试对这些生成的类进行检测,则由于仍然存在的检测错误以及对数量的依赖性,该代理将失败。调用可能是这种情况偶尔发生的原因。

While this bug in the Instrumentation/JVM should be fixed (and will be fixed in the next release), it would also help not trying to instrument these classes. 虽然应该修复了Instrumentation / JVM中的错误(并将在下一发行版中修复),但它也将有助于不尝试检测这些类。 Normally, there should be no reason to instrument these internal helper classes. 通常,没有理由对这些内部帮助程序类进行检测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM