harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r496745 - in /harmony/enhanced/classlib/trunk/modules: awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java swing/src/test/api/java/common/javax/swing/text/UtilitiesTest.java
Date Tue, 16 Jan 2007 16:07:04 GMT
Author: hindessm
Date: Tue Jan 16 08:07:03 2007
New Revision: 496745

URL: http://svn.apache.org/viewvc?view=rev&rev=496745
Log:
Applying patches from "[#HARMONY-2744] [classlib][swing]
j.s.text.Utilities.getNextWord throws IllegalArgumentException rather than
BadLocationException".

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/UtilitiesTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java?view=diff&rev=496745&r1=496744&r2=496745
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java
Tue Jan 16 08:07:03 2007
@@ -132,7 +132,7 @@
 
         BreakIterator bi = BreakIterator.getWordInstance();
         int length = doc.getLength();
-        if (pos < 0 || pos > length) {
+        if (pos < 0 || pos >= length) {
             // awt.2F=No more words
             throwException(Messages.getString("awt.2F"), pos); //$NON-NLS-1$
         }
@@ -143,13 +143,12 @@
 
         int iteratorNextWord = bi.following(pos);
         while (iteratorNextWord < length
-             && ((content.charAt(iteratorNextWord) == ' '
-             || content.charAt(iteratorNextWord) == '\n')
-             || content.charAt(iteratorNextWord) == '\t')) {
-             iteratorNextWord = bi.following(iteratorNextWord);
+               && Character.isWhitespace(content.charAt(iteratorNextWord))) {
+            iteratorNextWord = bi.following(iteratorNextWord);
         }
         if (iteratorNextWord == length) {
-             iteratorNextWord = 0;
+            // awt.2F=No more words
+            throwException(Messages.getString("awt.2F"), pos); //$NON-NLS-1$
         }
         return iteratorNextWord;
     }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/UtilitiesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/UtilitiesTest.java?view=diff&rev=496745&r1=496744&r2=496745
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/UtilitiesTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/UtilitiesTest.java
Tue Jan 16 08:07:03 2007
@@ -26,6 +26,7 @@
 import java.awt.Rectangle;
 import java.text.BreakIterator;
 import java.text.CharacterIterator;
+
 import javax.swing.JFrame;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
@@ -929,5 +930,47 @@
         getNextWordTest(jta);
         getNextWordTest(jtf);
         //getNextWordTest(jtp);
+    }
+
+    // HARMONY-2744
+    public void testGetNextWord02() {
+        jta = new JTextArea("");
+        try {
+            Utilities.getNextWord(jta, 0);
+            fail("BadLocationException expected");
+        } catch (BadLocationException e) {
+            // "No more words"
+        }
+    }
+
+    // HARMONY-2744
+    public void testGetNextWord03() {
+        jta = new JTextArea("a");
+        try {
+            Utilities.getNextWord(jta, 0);
+            fail("BadLocationException expected");
+        } catch (BadLocationException e) {
+            // "No more words"
+        }
+
+        try {
+            Utilities.getNextWord(jta, 1);
+            fail("BadLocationException expected");
+        } catch (BadLocationException e) {
+            // "No more words"
+        }
+    }
+
+    // HARMONY-2744
+    public void testGetNextWord04() throws Exception {
+        jta = new JTextArea("a b");
+        assertEquals(2, Utilities.getNextWord(jta, 0));
+        assertEquals(2, Utilities.getNextWord(jta, 1));
+        try {
+            Utilities.getNextWord(jta, 2);
+            fail("BadLocationException expected");
+        } catch (BadLocationException e) {
+            // "No more words"
+        }
     }
 }



Mime
View raw message