diff --git a/src/java.desktop/share/classes/java/awt/font/NumericShaper.java b/src/java.desktop/share/classes/java/awt/font/NumericShaper.java index 99b59cc2e0ec3..44b7b1a23fec6 100644 --- a/src/java.desktop/share/classes/java/awt/font/NumericShaper.java +++ b/src/java.desktop/share/classes/java/awt/font/NumericShaper.java @@ -1441,6 +1441,9 @@ public static NumericShaper getShaper(Range singleRange) { * EUROPEAN digits are encountered before any strong directional * text in the string, the context is presumed to be EUROPEAN, and * so the digits will not shape. + * Any bit set in the {@code ranges} bitmask which is not a + * recognised value is discarded. Similarly if two bits are + * specified where one takes precedence, the lesser one is discarded. * @param ranges the specified Unicode ranges * @return a shaper for the specified ranges */ @@ -1460,6 +1463,9 @@ public static NumericShaper getContextualShaper(int ranges) { * directional text in the string, the context is presumed to be * EUROPEAN, and so the digits will not shape. * + * If two ranges are specified where one takes precedence over the + * other the lesser range is discarded. + * * @param ranges the specified Unicode ranges * @return a contextual shaper for the specified ranges * @throws NullPointerException if {@code ranges} is {@code null}. @@ -1499,6 +1505,9 @@ public static NumericShaper getContextualShaper(int ranges, int defaultContext) * range is one of the provided ranges. The shaper uses {@code * defaultContext} as the starting context. * + * If two ranges are specified where one takes precedence over the + * other the lesser range is discarded. + * * @param ranges the specified Unicode ranges * @param defaultContext the starting context, such as * {@code NumericShaper.Range.EUROPEAN} @@ -1522,7 +1531,7 @@ public static NumericShaper getContextualShaper(Set ranges, */ private NumericShaper(int key, int mask) { this.key = key; - this.mask = mask; + this.mask = mask & (CONTEXTUAL_MASK | ALL_RANGES); if (((this.mask & ARABIC) != 0) && ((this.mask & EASTERN_ARABIC) != 0)) { this.mask &= ~ARABIC; } diff --git a/test/jdk/java/awt/font/NumericShaper/NSEqualsTest.java b/test/jdk/java/awt/font/NumericShaper/NSEqualsTest.java index 6af73b7efa2ff..cc1c078bf7937 100644 --- a/test/jdk/java/awt/font/NumericShaper/NSEqualsTest.java +++ b/test/jdk/java/awt/font/NumericShaper/NSEqualsTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8365077 + * @bug 8365077 8370160 * @summary confirm that an instance which is created with Enum ranges is * equal to another instance which is created with equivalent traditional * ranges, and that in such a case the hashCodes are also equal. @@ -38,6 +38,12 @@ public class NSEqualsTest { public static void main(String[] args) { + // Invalid ranges should be discarded + NumericShaper cs1 = + NumericShaper.getContextualShaper(NumericShaper.ALL_RANGES); + NumericShaper cs2 = NumericShaper.getContextualShaper(-1); + printAndCompare(cs1, cs2); + for (Range r1 : Range.values()) { test(r1); for (Range r2 : Range.values()) {