Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8273430

Suspicious duplicate condition in java.util.regex.Grapheme#isExcludedSpacingMark

XMLWordPrintable

    • b15
    • generic
    • generic

        Hello.
        I found suspicious condition in the method
        java.util.regex.Grapheme#isExcludedSpacingMark
        It's detected by IntelliJ IDEA inspection 'Condition is covered by
        further condition'
        https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/regex/Grapheme.java#L157

        ```
        private static boolean isExcludedSpacingMark(int cp) {
          return cp == 0x102B || cp == 0x102C || cp == 0x1038 ||
                  cp >= 0x1062 && cp <= 0x1064 ||
                  cp >= 0x1062 && cp <= 0x106D || // <== here is the warning
                  cp == 0x1083 ||
                  cp >= 0x1087 && cp <= 0x108C ||
                  cp == 0x108F ||
                  cp >= 0x109A && cp <= 0x109C ||
                  cp == 0x1A61 || cp == 0x1A63 || cp == 0x1A64 ||
                  cp == 0xAA7B || cp == 0xAA7D;
        }
        ```
        There are 2 sub-conditions in this complex condition:
        cp >= 0x1062 && cp <= 0x1064 ||
        cp >= 0x1062 && cp <= 0x106D ||

        The second condition is _wider_ than the first one.
        I believe it's a bug. The second condition (according to
        https://www.compart.com/en/unicode/category/Mc) should look like this:

        cp >= 0x1067 && cp <= 0x106D ||

        0x1065, 0x1066 are not from the Spacing_Mark category.


        Andrey Turbanov

              igraves Ian Graves
              jlaskey Jim Laskey
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: