问题描述
SEVERE: Servlet.service() for servlet [jsp] threw exception
java.lang.IllegalArgumentException: Invalid version number: Version number may be negative or greater than 255
at com.ibm.icu.util.VersionInfo.getInstance(VersionInfo.java:191)
at com.ibm.icu.impl.ICUDebug.getInstanceLenient(ICUDebug.java:65)
at com.ibm.icu.impl.ICUDebug.<clinit>(ICUDebug.java:69)
我认为这是由于某些版本不匹配所致。如何追踪问题?该应用程序未修改过,因此我不确定如何检查该问题。如果我知道哪个jarfile给了问题,那会很好。
解决方法
当我降级Java版本时,该问题已解决。
,TLDR;用 latest version 替换您的 icu4j.jar
文件。
这可能是由您的类路径中的旧版 ICU4J 引起的。 VersionInfo
类被限制为 2 个字符的版本号,将限制设置为 255。由于 Java 8 现在是 1.8.0_291,291
超过了 2 个字符的限制,导致 ICU4J VersionInfo 异常.
ICU-21219 已在 ICU4J:68.1 中修复
,好吧,我知道这是一个肮脏的黑客,但将“java.version”属性设置为不包含数字 >255 的版本对我有用:
System.setProperty("java.version","1.8.0_254");
只需在类加载前设置(第一次访问),然后恢复原始值。并向库的作者提交错误,因为这只是一种解决方法。
,如果您不想升级 ICU,只需在调用 ICU 内容之前调用这个小辅助函数即可:
/**
* There is a bug in an old ICU version that stops ICU from working when the JDK patch version is larger than
* 255 (like in jdk 1.8.0_261). To work around that we change the local version number,init ICU and change it
* back then.
*/
private void icuHack() {
String javaVersion = System.getProperty("java.version");
int idxOfUnderscore = javaVersion.indexOf('_');
if( idxOfUnderscore == -1 ) {
return;
}
int patchVersion = Integer.parseInt(javaVersion.substring(idxOfUnderscore+1));
if( patchVersion < 256 ) {
return;
}
log.info("Java version '"+javaVersion+"' contains patch version >255,need to do ICU hack.");
System.setProperty("java.version","1.8.0_254");
new com.ibm.icu.impl.ICUDebug();
System.setProperty("java.version",javaVersion);
}