I use Jersey version 1.18.1 (com.sun.jersey), Spring and Java 8. If I put a Java 8 Lambda expression in a REST service, it crashes. If I remove the lambda expression, it works.
@Service
@Path("/hello")
public class Hello {
@GET
public String hello() {
new ArrayList<String>().stream().filter((str) -> str.length() > 0);
return "hello";
}
}
I use com.sun.jersey (1.18.1 version).
Full stacktrace:
SEVERE: Allocate exception for servlet jersey-serlvet java.lang.ArrayIndexOutOfBoundsException: 52264
at jersey.repackaged.org.objectweb.asm.ClassReader.readClass(ClassReader.java:1976)
at jersey.repackaged.org.objectweb.asm.ClassReader.accept(ClassReader.java:464)
at jersey.repackaged.org.objectweb.asm.ClassReader.accept(ClassReader.java:420)
at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138)
at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86)
at com.sun.jersey.core.util.Closing.f(Closing.java:71)
Please tell me how to fix it.
Jersey 1.18 is not compatible with java 8. They added java 8 compatibility since 1.19.
If you take a look at the Jersey 1.19 release notes, you can see the introduced the jdk8 support.
https://github.com/jersey/jersey-1.x/releases/tag/1.19
Quoting the 1.19 tag:
Thanks to @cowwoc you're able to run Jersey 1.x applications on JDK8
To fix this you have to upgrade Jersey to 1.19 or downgrade java 8 to 7.
We had similar problem. Also com.sun.jersey in use.
After migration to the newest version (19.1) all works. So simply please upgrade to the newest version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With