RRR*_*R_J 1 java lambda java-8
我们的项目中有以下代码,虽然它工作正常但随机我们在运行时得到class def not found错误.我们的App服务器在每个星期日重新启动,因此有时我们会在任何随机服务器实例上收到此错误.服务器重启解决了问题,但任何线索都是为什么类加载中断.
我在这个问题上有一些类似的错误,似乎问题已在jdk 9中修复了.JR8中的lambdas转换
但在我得出结论之前,有人可以解释它是同一种错误,以及为什么偶尔会发生这种错误.
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;
}
Run Code Online (Sandbox Code Playgroud)
错误:-
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
Run Code Online (Sandbox Code Playgroud)
如果涉及到Instrumentation ,很可能你已经链接的bug确实适用.考虑这个错误,JDK-8027681,"一旦反射代理生成开始,Lambda序列化就会失败",这会影响执行超过16次的所有Reflection操作(这是一个可配置的阈值),因为底层实现将通过生成来优化后续调用一个访问器类,由HotSpot可以内联的字节码组成.此字节码无法访问早期版本的Java 8中为lambda表达式生成的匿名类.
虽然已修复此错误,但在一定数量的调用之后仍然存在所描述的生成类的行为,因此如果代理尝试检测这些生成的类,则由于仍存在的Instrumentation错误以及对数量的依赖性,它将失败.调用可能是偶尔发生这种情况的原因.
虽然应修复Instrumentation/JVM中的这个错误(并将在下一个版本中修复),但它也有助于不尝试检测这些类.通常,没有理由对这些内部帮助程序类进行检测.