[英]Sorting List throws ArrayIndexOutOfBoundsException
The following innocent API call crashes the entire Jersey web application. 以下无辜的API调用使整个Jersey Web应用程序崩溃。
@Path("/sortlist")
public class SortList {
@GET
public void sort() {
List<Dog> test = new ArrayList<>();
test.add(new Dog("test"));
test.add(new Dog("blah"));
test.sort(Comparator.comparing(Dog::getName));
}
class Dog {
private String name;
public String getName() { return name; }
public Dog(String name) { this.name = name; }
}
}
It throws 它抛出
javax.servlet.ServletException: Servlet.init() for servlet jersey-serlvet threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
root cause
java.lang.ArrayIndexOutOfBoundsException: 20343
org.objectweb.asm.ClassReader.<init>(Unknown Source)
But why? 但为什么? Even synchronizing the sorting operation has no effect.
即使同步分类操作也无效。 Could this be a bug in one of the following technologies?
这可能是下列技术之一的错误吗? Can you duplicate this problem?
您能重复这个问题吗?
Apparently this is a Jersey Bug 1.X, as it does not support Java 8 well enough. 显然,这是Jersey Bug 1.X,因为它对Java 8的支持不够好。 Upgrading to Jersey 2.X solves this problem.
升级到Jersey 2.X可解决此问题。
A Solution for jersey 1.X to this would be using a Java 7 approach for sorting. 球衣1.X的解决方案将使用Java 7方法进行排序。
Collections.sort(test, new Comparator<Dog>() {
@Override
public int compare(Dog o1, Dog o2) {
return o1.getName().compareTo(o2.getName());
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.