1

We have below code in our project and although it works fine but randomly we get class def not found error at runtime. Our App servers are restarted on each Sunday so sometimes we get this error on any random server instance. 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

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
Community
  • 1
  • 1
RRR_J
  • 345
  • 2
  • 6
  • 19
  • Is this happening during shutdown? – teppic Feb 16 '17 at 05:45
  • No, it happens whenever user is trying to access the module where isAttachmentWarningShown method gets invoked – RRR_J Feb 16 '17 at 06:15
  • 2
    I know this incompatibility between Reflection and anonymous classes, but I don’t understand why jboss is trying to invoke a method via Reflection on a `Predicate`. – Holger Feb 16 '17 at 08:52
  • 1
    How we can reproduce this behaviour to be sure that problem in lambda it self, but in params which you pass there? – Andremoniy Feb 16 '17 at 09:11
  • I understand but somehow this issue is not always reproducible, it's bit random. Also why would it give such error if at all there is anything wrong in param ? I have added the code for isAttachmentExpired method in question. – RRR_J Feb 16 '17 at 10:33

1 Answers1

5

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. This bytecode failed to access the anonymous classes generated for lambda expressions in early version of Java 8.

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. Normally, there should be no reason to instrument these internal helper classes.

Community
  • 1
  • 1
Holger
  • 285,553
  • 42
  • 434
  • 765
  • Thanks for referring to this bug but we are already on jdk 1.8.0_111 which is after this bug was resolved. – RRR_J Feb 16 '17 at 11:25
  • also the application is deployed on weblogic and the trace in error referring to 'jboss' is actually because the class which has this method is a jboss seam component. – RRR_J Feb 16 '17 at 11:30
  • 1
    Ok, so it’s rather related to whatever instrumentation is applied to it (doesn’t really matter whether its “jboss” or “jboss seam component”). The statement still holds, it’s unclear what this interception is trying to achieve. – Holger Feb 16 '17 at 12:22