Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Struts 2 compatible with Java 8 (legacy ASM 3)

I'm using Struts 2 with Convention plugin. Struts 2 depends on ASM 3.3 which isn't compatible with Java 8. It fails to discover action classes that contain lambdas or method references.

The exception:

2014-06-27 18:47:32,958 ERROR main/com.opensymphony.xwork2.util.finder.ClassFinder: Unable to read class [my.project.Action]
java.lang.ArrayIndexOutOfBoundsException: 30305
    at org.objectweb.asm.ClassReader.readClass(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at com.opensymphony.xwork2.util.finder.ClassFinder.readClassDef(ClassFinder.java:717)
    at com.opensymphony.xwork2.util.finder.ClassFinder.<init>(ClassFinder.java:112)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.findActions(PackageBasedActionConfigBuilder.java:390)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:347)
    at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:268)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:489)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)

ASM 5 seems to support Java 8 but Struts isn't binary compatible with that.

Are there any workarounds for this problems? Right now I'm considering patching Struts/XWork.

like image 998
alamar Avatar asked Jun 27 '14 15:06

alamar


People also ask

Is Struts 1. 3 compatible with Java 8?

When upgraded to Java 8, we managed to run the application with Struts 1.3 however I now need to update the Java to 11 or 12 version.

Is Struts 2 still used?

Struts 2 development is still active and, as of writing this article, the newest version is 2.5.

What is Struts 2 used for?

Apache Struts 2 is an open-source web application framework for developing Java EE web applications. It uses and extends the Java Servlet API to encourage developers to adopt a model–view–controller (MVC) architecture.


1 Answers

Guess what - I had to patch the thing.

The gist of it: https://gist.github.com/anonymous/017b23c1d7c97c37d167

like image 50
alamar Avatar answered Sep 17 '22 16:09

alamar