Skip to content

Commit 4b31511

Browse files
committed
8370160: NumericShaper allows illegal ranges
Reviewed-by: serb, psadhukhan, kizune
1 parent d18e815 commit 4b31511

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/java.desktop/share/classes/java/awt/font/NumericShaper.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,9 @@ public static NumericShaper getShaper(Range singleRange) {
14411441
* EUROPEAN digits are encountered before any strong directional
14421442
* text in the string, the context is presumed to be EUROPEAN, and
14431443
* so the digits will not shape.
1444+
* Any bit set in the {@code ranges} bitmask which is not a
1445+
* recognised value is discarded. Similarly if two bits are
1446+
* specified where one takes precedence, the lesser one is discarded.
14441447
* @param ranges the specified Unicode ranges
14451448
* @return a shaper for the specified ranges
14461449
*/
@@ -1460,6 +1463,9 @@ public static NumericShaper getContextualShaper(int ranges) {
14601463
* directional text in the string, the context is presumed to be
14611464
* EUROPEAN, and so the digits will not shape.
14621465
*
1466+
* If two ranges are specified where one takes precedence over the
1467+
* other the lesser range is discarded.
1468+
*
14631469
* @param ranges the specified Unicode ranges
14641470
* @return a contextual shaper for the specified ranges
14651471
* @throws NullPointerException if {@code ranges} is {@code null}.
@@ -1499,6 +1505,9 @@ public static NumericShaper getContextualShaper(int ranges, int defaultContext)
14991505
* range is one of the provided ranges. The shaper uses {@code
15001506
* defaultContext} as the starting context.
15011507
*
1508+
* If two ranges are specified where one takes precedence over the
1509+
* other the lesser range is discarded.
1510+
*
15021511
* @param ranges the specified Unicode ranges
15031512
* @param defaultContext the starting context, such as
15041513
* {@code NumericShaper.Range.EUROPEAN}
@@ -1522,7 +1531,7 @@ public static NumericShaper getContextualShaper(Set<Range> ranges,
15221531
*/
15231532
private NumericShaper(int key, int mask) {
15241533
this.key = key;
1525-
this.mask = mask;
1534+
this.mask = mask & (CONTEXTUAL_MASK | ALL_RANGES);
15261535
if (((this.mask & ARABIC) != 0) && ((this.mask & EASTERN_ARABIC) != 0)) {
15271536
this.mask &= ~ARABIC;
15281537
}

test/jdk/java/awt/font/NumericShaper/NSEqualsTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8365077
26+
* @bug 8365077 8370160
2727
* @summary confirm that an instance which is created with Enum ranges is
2828
* equal to another instance which is created with equivalent traditional
2929
* ranges, and that in such a case the hashCodes are also equal.
@@ -38,6 +38,12 @@ public class NSEqualsTest {
3838

3939
public static void main(String[] args) {
4040

41+
// Invalid ranges should be discarded
42+
NumericShaper cs1 =
43+
NumericShaper.getContextualShaper(NumericShaper.ALL_RANGES);
44+
NumericShaper cs2 = NumericShaper.getContextualShaper(-1);
45+
printAndCompare(cs1, cs2);
46+
4147
for (Range r1 : Range.values()) {
4248
test(r1);
4349
for (Range r2 : Range.values()) {

0 commit comments

Comments
 (0)