harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r495897 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/DefaultFormatter.java test/api/java/common/javax/swing/JFormattedTextFieldTest.java
Date Sat, 13 Jan 2007 13:06:04 GMT
Author: hindessm
Date: Sat Jan 13 05:06:03 2007
New Revision: 495897

URL: http://svn.apache.org/viewvc?view=rev&rev=495897
Log:
Applied patches from "[#HARMONY-2523] [classlib][swing]
j.s.text.JFormattedTextField(Object) throws NPE when
Object.toString() == null".

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/DefaultFormatter.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFormattedTextFieldTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/DefaultFormatter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/DefaultFormatter.java?view=diff&rev=495897&r1=495896&r2=495897
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/DefaultFormatter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/DefaultFormatter.java
Sat Jan 13 05:06:03 2007
@@ -14,10 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Evgeniya G. Maenkova
- * @version $Revision$
- */
 package javax.swing.text;
 
 import java.io.Serializable;
@@ -30,9 +26,21 @@
 import javax.swing.SwingUtilities;
 import javax.swing.text.DocumentFilter.FilterBypass;
 
+/**
+ * <p>
+ * <i>DefaultFormatter</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared
as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
+ */
 public class DefaultFormatter extends JFormattedTextField.AbstractFormatter
     implements Cloneable, Serializable {
 
+    private static final long serialVersionUID = 4759164676455607130L;
+
     private boolean commitsOnValidEdit;
     private boolean allowsInvalid = true;
     private boolean overwriteMode = true;
@@ -41,6 +49,7 @@
 
     private class DocumentFilterImpl extends DocumentFilter {
 
+        @Override
         public void insertString(final FilterBypass filterBypass,
                                  final int offset,
                                  final String string,
@@ -55,12 +64,14 @@
             }
         }
 
+        @Override
         public void remove(final FilterBypass filterBypass,
                            final int offset, final int length)
                 throws BadLocationException {
             removeImpl(filterBypass, offset, length);
         }
 
+        @Override
         public void replace(final FilterBypass filterBypass,
                             final int offset, final int length,
                             final String text,
@@ -68,7 +79,7 @@
             throws BadLocationException {
             if (overwriteMode) {
                 int strLength = getMaxLengthToRemove(filterBypass, offset,
-                                           Math.max(length, text.length()));
+                        Math.max(length, text != null ? text.length() : 0));
                 replaceImpl(filterBypass, offset, strLength, text, attrs);
             } else {
                 replaceImpl(filterBypass, offset, length, text, attrs);
@@ -181,6 +192,7 @@
 
     }
 
+    @Override
     public Object clone() throws CloneNotSupportedException {
         return super.clone();
     }
@@ -193,6 +205,7 @@
         return commitsOnValidEdit;
     }
 
+    @Override
     protected DocumentFilter getDocumentFilter() {
         if (documentFilter == null) {
             documentFilter = new DocumentFilterImpl();
@@ -216,6 +229,7 @@
         this.commitsOnValidEdit = commitsOnValidEdit;
     }
 
+    @Override
     protected void setEditValid(final boolean isEditValid) {
         super.setEditValid(isEditValid);
         SwingUtilities.invokeLater(new Runnable() {
@@ -235,7 +249,7 @@
     }
 
     private Object stringToValue(final String string, final Class valueClass) {
-        return AccessController.doPrivileged(new PrivilegedAction() {
+        return AccessController.doPrivileged(new PrivilegedAction<Object>() {
             public Object run() {
                 Constructor constructor = null;
                 try {
@@ -257,6 +271,7 @@
          });
     }
 
+    @Override
     public Object stringToValue(final String string) throws ParseException {
         final Class valueClass = (this.valueClass != null) ? this.valueClass
                 : getTextFieldValueClass();
@@ -270,6 +285,7 @@
        return result;
     }
 
+    @Override
     public String valueToString(final Object value) throws ParseException {
         return value != null ? value.toString() : "";
     }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFormattedTextFieldTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFormattedTextFieldTest.java?view=diff&rev=495897&r1=495896&r2=495897
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFormattedTextFieldTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFormattedTextFieldTest.java
Sat Jan 13 05:06:03 2007
@@ -192,6 +192,17 @@
         assertNull(factory.getNullFormatter());
     }
 
+    public void testJFormattedTextFieldObject_NullToString() {
+        final Object value = new Object() {
+            @Override
+            public String toString() {
+                return null;
+            }
+        };
+        final JFormattedTextField ftf = new JFormattedTextField(value);
+        assertEquals("", ftf.getText());
+    }
+
     public void testJFormattedTextFieldAbstractFormatter() {
         InternationalFormatter formatter = new InternationalFormatter();
         JFormattedTextField tf1 = new JFormattedTextField(formatter);



Mime
View raw message