Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/java.desktop/share/classes/java/awt/font/NumericShaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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}.
Expand Down Expand Up @@ -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}
Expand All @@ -1522,7 +1531,7 @@ public static NumericShaper getContextualShaper(Set<Range> ranges,
*/
private NumericShaper(int key, int mask) {
this.key = key;
this.mask = mask;
this.mask = mask & (CONTEXTUAL_MASK | ALL_RANGES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will accept the CONTEXTUAL_MASK even if it was provided by the app. It is unclear whether we should discard it in that case or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always added by the implementation when constructing a contextual shaper.
So when we get here it is always part of the mask argument.
The only path that gets here without a contextual shaper bit set is the single range case.
But it the app has set that there an IAE is thrown, so it can't happen.

if (((this.mask & ARABIC) != 0) && ((this.mask & EASTERN_ARABIC) != 0)) {
this.mask &= ~ARABIC;
}
Expand Down
8 changes: 7 additions & 1 deletion test/jdk/java/awt/font/NumericShaper/NSEqualsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()) {
Expand Down