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

Query.match code for character sequences like [a-z] is wrong

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-svc
    • None
    • 5.0
    • b43
    • generic
    • generic

      From ###@###.###:

      The logic in the javax.management.MatchQueryExp.wildmatch() method
      appears to be flawed with respect to character range matching.

      wildmatch( "2[7-9]", "21" ) incorrectly returns 'true'

      The problem lies in the following code block:

          while (++pi < plen && (c = p.charAt(pi)) != ']') {
              if (p.charAt(pi) == '-' && pi+1 < plen) {
                  if (s.charAt(si) >= c && s.charAt(si) <= p.charAt(pi+1)) {
                      seenit = true;
                  }
                  pi += 1;
              } else {
                  if (c == s.charAt(si)) {
                      seenit = true;
                  }
              }
          }

      The comparison expression 's.charAt(si) >= c' in the third line will
      incorrectly compare the character 's.charAt(si)' against '-'.

      When I modified the expression to 's.charAt(si) >= p.charAt(pi-1)',
      the example above correctly returned 'false'.
      ###@###.### 2005-05-06 11:24:50 GMT

            lmalvent Luis-Miguel Alventosa (Inactive)
            emcmanus Eamonn McManus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: