See an InvalidBytecodeException when an EJB application is deployed in a EAP6 server using Java8

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Issue

  • If the application is deployed with Java 8 the show Exception is thrown. The same application works correct if build and deployed with Java7
ERROR [org.jboss.msc.service.fail] (MSC service thread 1-12) MSC000001: Failed to start service jboss.deployment.subunit."simpleEJB30.ear"."ejb.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."simpleEJB30.ear"."ejb.jar".INSTALL: JBAS018733: Failed to process phase INSTALL of subdeployment "ejb.jar" of deployment "simpleEJB30.ear"
	at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [jboss-as-server-7.5.8.Final-redhat-2.jar:7.5.8.Final-redhat-2]
	...
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011030: Could not configure component LocalSLSBean
	...
Caused by: org.jboss.classfilewriter.InvalidBytecodeException: Cannot load variable at 0. Local Variables: Local Variables: []
	at org.jboss.classfilewriter.code.CodeAttribute.aload(CodeAttribute.java:172)
	at org.jboss.invocation.proxy.ProxyFactory$ProxyMethodBodyCreator.overrideMethod(ProxyFactory.java:86) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]
	at org.jboss.invocation.proxy.AbstractSubclassFactory.overrideMethod(AbstractSubclassFactory.java:106) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]
	at org.jboss.invocation.proxy.AbstractSubclassFactory.addInterface(AbstractSubclassFactory.java:363) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]
	at org.jboss.invocation.proxy.ProxyFactory.generateClass(ProxyFactory.java:286) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]
	at org.jboss.invocation.proxy.AbstractClassFactory.buildClassDefinition(AbstractClassFactory.java:207) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]
	at org.jboss.invocation.proxy.AbstractClassFactory.defineClass(AbstractClassFactory.java:160) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]
	at org.jboss.invocation.proxy.AbstractProxyFactory.getCachedMethods(AbstractProxyFactory.java:150) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]
	at org.jboss.as.ejb3.component.stateless.StatelessComponentDescription$3.configure(StatelessComponentDescription.java:150)
	at org.jboss.as.ee.component.DefaultComponentViewConfigurator.configure(DefaultComponentViewConfigurator.java:68)
	at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:80)
	... 6 more

Resolution

The issue is tracked by
This content is not included.EAP6 BZ1346242
Content from issues.jboss.org is not included.WildFly WFLY-4316

Root Cause

The issue appear if an EJB interface declare static methods (Java 8 - default methods) like this:

@Local
public interface LocalSLS {
    ...
     public static int returnSoemthing() {
      return 0;
    }
}

But this might also happen if the interface does not include it but implement an interface which changed from Java7 to Java8 and include default methods

As example the Comparator which use default methods:
Java7

public interface Comparator<T> {
  int compare(T o1, T o2);
  boolean equals(Object obj);
}

Java8

@FunctionalInterface
public interface Comparator<T> {
  int compare(T o1, T o2);
  boolean equals(Object obj);
  ...
  public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() {...}
  ...
  public static<T> Comparator<T> comparingDouble(ToDoubleFunction<? super T> keyExtractor) {...}
}

If you have now an EJB interface that extends an Interface which changed from Java7 to Java8 like this the application deployment will fail if the server is started with Java8 instead of Java7.

Diagnostic Steps

  • check whether the application EJB Interfaces use default methods from Java8
  • check whether any EJB inteface of the application extends Java interfaces which might be Functional or contain default methods
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.