3

I'm working on a Portlet project using Java8 and Spring 4.1.5

I have a class annotated with @Service that includes this line (same failure with any closure)

user.getOrganizations().stream().forEach(o -> System.out.println(o));

When I deploy my webapp I get the following error (omitting the massive stack-trace)

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\dev\liferay-developer-studio\DeveloperStudio\workspace\somepath\service\MyService.class];
     nested exception is java.lang.ArrayIndexOutOfBoundsException: 52264
....
Caused by: java.lang.ArrayIndexOutOfBoundsException: 52264
    at org.springframework.asm.ClassReader.readClass(Unknown Source)

My dependencies in MVN look like:

myGroupId:myArtifactId:war:0.0.0-SNAPSHOT
+- com.liferay.portal:portal-service:jar:6.2.10.11:provided
+- com.liferay.portal:util-bridges:jar:6.2.10.11:provided
+- com.liferay.portal:util-java:jar:6.2.10.11:provided
+- com.liferay.portal:util-taglib:jar:6.2.10.11:provided
+- javax.portlet:portlet-api:jar:2.0:provided
+- javax.servlet:servlet-api:jar:2.5:provided
+- javax.servlet.jsp:jsp-api:jar:2.2:provided
+- org.springframework:spring-webmvc-portlet:jar:4.1.5.RELEASE:provided
|  +- org.springframework:spring-beans:jar:4.1.5.RELEASE:provided
|  +- org.springframework:spring-context:jar:4.1.5.RELEASE:provided
|  |  +- org.springframework:spring-aop:jar:4.1.5.RELEASE:provided
|  |  |  \- aopalliance:aopalliance:jar:1.0:provided
|  |  \- org.springframework:spring-expression:jar:4.1.5.RELEASE:provided
|  +- org.springframework:spring-core:jar:4.1.5.RELEASE:provided
|  |  \- commons-logging:commons-logging:jar:1.2:provided
|  +- org.springframework:spring-web:jar:4.1.5.RELEASE:provided
|  \- org.springframework:spring-webmvc:jar:4.1.5.RELEASE:provided
+- org.springframework:spring-test:jar:4.1.5.RELEASE:test
+- org.mockito:mockito-all:jar:1.10.8:test
+- junit:junit:jar:4.11:test
|  \- org.hamcrest:hamcrest-core:jar:1.3:test
+- org.powermock:powermock-module-junit4:jar:1.5.1:test
|  \- org.powermock:powermock-module-junit4-common:jar:1.5.1:test
|     \- org.powermock:powermock-reflect:jar:1.5.1:test
|        \- org.objenesis:objenesis:jar:1.2:test
+- org.powermock:powermock-module-junit4-rule-agent:jar:1.5.1:test
|  +- org.powermock:powermock-module-javaagent:jar:1.5.1:test
|  \- org.powermock:powermock-core:jar:1.5.1:test
|     \- org.javassist:javassist:jar:3.18.0-GA:test
\- org.powermock:powermock-api-mockito:jar:1.5.1:test
   \- org.powermock:powermock-api-support:jar:1.5.1:test

Every solution that I've found so far says "If you are using spring 3 update to spring 4" but I'm already using it

Any ideas?

Cheers

Scorpio
  • 2,309
  • 1
  • 27
  • 45
Totò
  • 1,824
  • 15
  • 20
  • 1
    Why is cglib at the top level of the dependency tree? I'd expect that to be a transitive dependency of Spring, not declared explicitly. – skaffman Apr 09 '15 at 01:49
  • You are right, thanks for pointing it out. I've removed CGLIB but I still get the same error – Totò Apr 09 '15 at 02:18
  • Can you post your `@Service` annotated class? Where exactly is that line? – Rohit Jain Apr 09 '15 at 04:49
  • Thanks for your interest @RohitJain, I can post the code but it's pointless, as long as I put a closure in any spring bean my code it breaks. I think I've found out why and I'm about to post it. Thanks again – Totò Apr 09 '15 at 04:53
  • Java8 is supported only from Spring4 onwards! – Jatin Apr 09 '15 at 12:00
  • Possible duplicate of [Failed to load ApplicationContext caused by ArrayIndexOutOfBoundsException in ClassReader](https://stackoverflow.com/questions/17563149/failed-to-load-applicationcontext-caused-by-arrayindexoutofboundsexception-in-cl) – rogerdpack Nov 02 '17 at 16:36

1 Answers1

2

Turns out that the issue is the container I'm working with - Liferay - has an older version of Spring (3.something).

The dependencies in my pom are provided; in addition in my liferay-plugin-package.properties the property portal-dependency-jars had the spring jars in the list.

This means that my plugin was using the Liferay's libs which have an older version of ASM unable to parse bytecode of classes using the new Java8 syntactical features, hence the breakage.

To solve it I got rid of the spring jars from liferay-plugin-package.properties and set the scope for spring in my pom to compile. This solved the problem.

(Note: Liferay doesn't officially support Java 8 at the moment so they are not meant to upgrade their spring version yet)

Totò
  • 1,824
  • 15
  • 20