7

I am getting below error when I try to access a page in my application.

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)

I assume that it is due to some version mismatch. How can I trace the issue? The application is not mavenized and hence I am not sure how to check the issue. Atleast if I know which jarfile is giving issue then it will be good.

JAVA_CAT
  • 737
  • 3
  • 13
  • 33
  • 1
    If https://findjar.com is working, you can use `findjar com.ibm.icu.util.VersionInfo` to see what jar files the class is commonly found in (in this case `icu4j.jar`). Subsequent searches for 'icu4j invalid java version' might lead you to the bug report `ICU-21219` or using https://mvnrepository.com/artifact/com.ibm.icu/icu4j you can find and download the latest version. – Thomas Taylor May 11 '21 at 22:22

8 Answers8

15

TLDR; replace your icu4j.jar file with the latest version.

This is likely caused by an older version of ICU4J in your classpath. The VersionInfo class was limited to 2-character version numbers, setting a limit to 255. Since Java 8 is now at 1.8.0_291, the 291 exceeds the 2-character limit, causing the ICU4J VersionInfo exception.

ICU-21219 is fixed in ICU4J:68.1

Thomas Taylor
  • 1,311
  • 14
  • 15
10

The problem is resolved as I downgraded my java version.

JAVA_CAT
  • 737
  • 3
  • 13
  • 33
  • to which version you downgraded? – sanket patel Jan 19 '21 at 08:53
  • 1
    <= 255 :) this isn`t a real solution, but a workaround... the solution would be fixing the code that produces such errors – torno Jan 25 '21 at 14:51
  • @sanketpatel 1.8.0_261 to 1.8.0.252 , currently I am using openjdk. – JAVA_CAT Jan 27 '21 at 15:14
  • @torno yeah correct. But the above question is to understand the issue, I have no clue about which code is giving issue. – JAVA_CAT Jan 27 '21 at 15:17
  • 1
    The problem is in `icu4j.jar` - replace that jar in your classpath with a newer version (68.1 or later). – Thomas Taylor May 11 '21 at 22:16
  • I didn't upgraded icu4j yet but in can see same error handling in 68.1 and higher version, for VersionInfo.java if (major < 0 || major > 255 || minor < 0 || minor > 255 || milli < 0 || milli > 255 || micro < 0 || micro > 255) { throw new IllegalArgumentException(INVALID_VERSION_NUMBER_); } – MANVENDRA LODHI Oct 13 '21 at 06:07
2

If you don't want to upgrade ICU just call this little helper function before the ICU stuff get's called:

/**
 * 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);
}
Daniel
  • 27,718
  • 20
  • 89
  • 133
  • Not pretty; not pretty at all (so thanks, and go wash your mouth out now!). But I can confirm that this does work. I changed the java.version to `hackVersion = javaVersion.substring(0, idxOfUnderscore+1) + "254";` in fact, in a possibly fanciful attempt to Do The Right Thing. Of course, the real Right Thing is for me to rewrite, to avoid the library that depends on this ancient version of icu4j. Perhaps later... – Norman Gray Nov 23 '21 at 17:02
1

Well, I know it is a dirty hack but setting the "java.version" property to a version that doesn't contain numbers >255 worked for me:

System.setProperty("java.version", "1.8.0_254");

Just set it before the class is loaded (first access) and restore the original value afterwards. And file a bug to the author of the library since this is just a workaround.

René
  • 71
  • 7
1

I solved this problem by excluding old icu4j package,eg:

    <dependency>
        <groupId>jaxen</groupId>
        <artifactId>jaxen</artifactId>
        <version>1.1.6</version>
        <exclusions>
            <exclusion>
                <groupId>com.ibm.icu</groupId>
                <artifactId>icu4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

then refer to the latest icu4j package:

    <dependency>
        <groupId>com.ibm.icu</groupId>
        <artifactId>icu4j</artifactId>
        <version>68.2</version>
    </dependency>
Brook
  • 109
  • 1
  • 7
0

I solved the problem by updating from 8.0.0.0 to 9.1.0.0

<dependency>
  <groupId>com.ibm.ctg</groupId>
  <artifactId>ctgclient</artifactId>
  <version>9.1.0.0</version>
</dependency>
0

As posted on https://academy.jahia.com/training-kb/knowledge-base/invalid-version-number-version-number-may-be-negative-or-greater-than-255

Cause There is a very high probability that before the restart, your JDK has been upgraded to a version greater than 255, leading to a known bug in the library icu4J (cf internal ticket QA-13064).

Solution If you're unable to upgrade to the OpenJDK 11, please follow these steps for each node:

  1. Stop your node
  2. Rename the library TOMCAT_HOME/webapps/ROOT/WEB-INF/lib/icu4j-4.0.1.jar with the suffix .bak
  3. In the same folder, add the library icu4j-67.1.jar
  4. Start your node

This also works if you are just upgrading Java sub version. For example from 1.8.0_211 to 1.8.0_311

0

I was able to solve it by switching to Java version compatible with Jenkins. Please note that below steps will only work if you have multiple Java versions installed on your system. Following are the steps taken :

  1. Check other Java version using below command: sudo update-alternatives --config java

  2. Select the compatible java version

  3. Restart jenkins

Hope it helps! Please let me know if you need further clarifications.

Aniket A
  • 1
  • 1