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

java.text.BreakIterator.isBoundary(int offset) fails when beginIndex > 0

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: dfC67450 Date: 06/29/98



      The methods java.text.BreakIterator.isBoundary(int offset) does not throw
      IllegalArgumentException in case of offset == 0 when begin index of text for
      scanning is greater than 0. But it does it if offset == 1.

      Here is the test demonstrating the bug:

      --------- Test.java ----------
      import java.text.*;

      import java.text.*;

      public class Test {
          public static void main (String args[]){
              boolean passed = true;
              BreakIterator iter = BreakIterator.getWordInstance();
              String str = "...Hello, World!...";
              int begin = 3;
              int end = str.length() - 3;
              iter.setText(new StringCharacterIterator(str, begin, end, begin));
              System.out.println("string for canning: \"" + str + "\"");
              System.out.println("begin: " + begin);
              System.out.println("end: " + end);
              System.out.println();
              for (int index = -1; index <= begin + 1; index ++) {
                try {
                    boolean returned = iter.isBoundary(index); // call method under test
                    System.out.print(" isBoundary(" + index + "): " + returned);
                    if (index < begin) {
                      passed = false;
                      System.out.print(" (should throw IllegalArgumentException)");
                    }
                } catch (IllegalArgumentException e) {
                    System.out.print(" isBoundary(" + index + "): IllegalArgumentException");
                    if (index == begin) {
                      passed = false;
                      System.out.print(" (should return true)");
                    }
                }
                System.out.println();
              }
              System.out.println();
              if (passed) {
                System.out.println("Test passed");
              } else {
                System.out.println("Test failed");
              }
          }
      }
      ---------Output from the test---------------------
      string for canning: "...Hello, World!..."
      begin: 3
      end: 16

        isBoundary(-1): IllegalArgumentException
        isBoundary(0): true (should throw IllegalArgumentException)
        isBoundary(1): IllegalArgumentException
        isBoundary(2): IllegalArgumentException
        isBoundary(3): IllegalArgumentException (should return true)
        isBoundary(4): false

      Test failed
      --------------------------------------------------

      ======================================================================

            rgillamsunw Richard Gillam (Inactive)
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: