From ab08fac17025dd9c166038160fd2042b10dcb2f1 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Wed, 19 Aug 2020 15:08:25 -0400 Subject: [PATCH] ICU-21219 Fix for Java version number overflow problem Internal API VersionInfo.javaVersion() maps Java version number to 4 integer fields. Each field must be up to 255. However, recent OpenJDK 8 update exceed this range. Luckily, we have only one reference in our code base for checking Java version. CharsetUTF16 uses maxBytePerChar = 4 for Java 5 and older, maxBytePerChar = 2 for newer Java version. Because we no longer support Java 5 runtime, we don't need this conditional check. We don't have any other uses of VersionInfo.javaVersion(). Java's version range is not what we can control, so I decided to delete the internal use only API completely. --- .../src/com/ibm/icu/charset/CharsetUTF16.java | 12 ++--- .../src/com/ibm/icu/util/VersionInfo.java | 50 ------------------- 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetUTF16.java b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetUTF16.java index a401441b2c5f..13f703a9a91c 100644 --- a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetUTF16.java +++ b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetUTF16.java @@ -17,7 +17,6 @@ import com.ibm.icu.text.UTF16; import com.ibm.icu.text.UnicodeSet; -import com.ibm.icu.util.VersionInfo; /** * @author Niti Hantaweepant @@ -65,13 +64,10 @@ public CharsetUTF16(String icuCanonicalName, String javaCanonicalName, String[] this.endianXOR = ENDIAN_XOR_LE; } - /* UnicodeBig and UnicodeLittle requires maxBytesPerChar set to 4 in Java 5 or less */ - if ((VersionInfo.javaVersion().getMajor() == 1 && VersionInfo.javaVersion().getMinor() <= 5) - && (isEndianSpecified && version == 1)) { - maxBytesPerChar = 4; - } else { - maxBytesPerChar = 2; - } + // UnicodeBig and UnicodeLittle used to require maxBytesPerChar set to 4 in Java 5 or less, + // but it's no longer necessary for newer Java versions. Java 5 or older runtime is no + // longer supported. + maxBytesPerChar = 2; minBytesPerChar = 2; maxCharsPerByte = 1; diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java b/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java index 8a418aee6f08..48a2b4f0504a 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java @@ -372,56 +372,6 @@ public static VersionInfo getInstance(int major) return getInstance(major, 0, 0, 0); } - private static volatile VersionInfo javaVersion; - - /** - * @internal - * @deprecated This API is ICU internal only. - */ - @Deprecated - public static VersionInfo javaVersion() { - if (javaVersion == null) { - synchronized(VersionInfo.class) { - if (javaVersion == null) { - String s = System.getProperty("java.version"); - // clean string - // preserve only digits, separated by single '.' - // ignore over 4 digit sequences - // does not test < 255, very odd... - - char[] chars = s.toCharArray(); - int r = 0, w = 0, count = 0; - boolean numeric = false; // ignore leading non-numerics - while (r < chars.length) { - char c = chars[r++]; - if (c < '0' || c > '9') { - if (numeric) { - if (count == 3) { - // only four digit strings allowed - break; - } - numeric = false; - chars[w++] = '.'; - ++count; - } - } else { - numeric = true; - chars[w++] = c; - } - } - while (w > 0 && chars[w-1] == '.') { - --w; - } - - String vs = new String(chars, 0, w); - - javaVersion = VersionInfo.getInstance(vs); - } - } - } - return javaVersion; - } - /** * Returns the String representative of VersionInfo in the format of * "major.minor.milli.micro"