harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r513746 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/datatransfer/DataFlavor.java test/api/java/common/java/awt/datatransfer/DataFlavorTest.java
Date Fri, 02 Mar 2007 13:14:49 GMT
Author: apetrenko
Date: Fri Mar  2 05:14:49 2007
New Revision: 513746

URL: http://svn.apache.org/viewvc?view=rev&rev=513746
Log:
Patch for HARMONY-2033 "[classlib][awt] DataFlavor equals, getParameter, isMimeTypeEqual and
selectBestTextFlavor throw unexpected exceptions"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/datatransfer/DataFlavorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java?view=diff&rev=513746&r1=513745&r2=513746
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java
Fri Mar  2 05:14:49 2007
@@ -196,7 +196,7 @@
     }
 
     private String getCharset() {
-        if (isCharsetRedundant()) {
+        if ((mimeInfo == null) || isCharsetRedundant()) {
             return ""; //$NON-NLS-1$
         }
         String charset = mimeInfo.getParameter("charset"); //$NON-NLS-1$
@@ -259,7 +259,7 @@
         if (lowerName.equals("humanpresentablename")) { //$NON-NLS-1$
             return humanPresentableName;
         }
-        return mimeInfo.getParameter(lowerName);
+        return mimeInfo != null ? mimeInfo.getParameter(lowerName) : null;
     }
 
     public String getHumanPresentableName() {
@@ -325,7 +325,8 @@
     }
 
     public final boolean isMimeTypeEqual(DataFlavor dataFlavor) {
-        return mimeInfo.equals(dataFlavor.mimeInfo);
+        return mimeInfo != null ? mimeInfo.equals(dataFlavor.mimeInfo)
+                : (dataFlavor.mimeInfo == null);
     }
 
     public boolean isMimeTypeEqual(String mimeType) {
@@ -464,7 +465,7 @@
         if (equals(stringFlavor) || equals(plainTextFlavor)) {
             return true;
         }
-        if (!mimeInfo.getPrimaryType().equals("text")) { //$NON-NLS-1$
+        if ((mimeInfo != null) && !mimeInfo.getPrimaryType().equals("text")) { //$NON-NLS-1$
             return false;
         }
 
@@ -702,14 +703,16 @@
     }
 
     private boolean isUnicodeFlavor() {
-        return (representationClass.equals(Reader.class) ||
-                representationClass.equals(String.class) ||
-                representationClass.equals(CharBuffer.class) ||
-                representationClass.equals(char[].class));
+        return (representationClass != null) 
+                && (representationClass.equals(Reader.class) 
+                || representationClass.equals(String.class) 
+                || representationClass.equals(CharBuffer.class) 
+                || representationClass.equals(char[].class));
     }
 
     private boolean isByteCodeFlavor() {
-        return (representationClass.equals(InputStream.class)
+        return (representationClass != null) 
+                && (representationClass.equals(InputStream.class)
                 || representationClass.equals(ByteBuffer.class)
                 || representationClass.equals(byte[].class));
     }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/datatransfer/DataFlavorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/datatransfer/DataFlavorTest.java?view=diff&rev=513746&r1=513745&r2=513746
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/datatransfer/DataFlavorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/datatransfer/DataFlavorTest.java
Fri Mar  2 05:14:49 2007
@@ -65,6 +65,9 @@
                 (Object) new DataFlavor("x/y; class=java.util.List; charset=c2", "")));
         assertTrue(!new DataFlavor("z/y; class=java.util.LinkedList", "").equals(
                 new RuntimeException()));
+
+        // Regression for HARMONY-2033
+        assertFalse(new DataFlavor().equals("")); //$NON-NLS-1$
     }
 
     /*
@@ -233,6 +236,9 @@
     public final void testGetParameter() {
         assertEquals(new DataFlavor("x/y; param=value", "z").getParameter("param"), "value");
         assertEquals(new DataFlavor("x/y; param=value", "z").getParameter("humanPresentableName"),
"z");
+        
+        // Regression for HARMONY-2033
+        assertNull(new DataFlavor().getParameter("")); //$NON-NLS-1$
     }
 
     public final void testGetHumanPresentableName() {
@@ -374,6 +380,9 @@
                 isMimeTypeEqual(new DataFlavor("z/y; param=value", "2")));
         assertFalse(new DataFlavor("x/y; class=java.io.Serializable", "1").
                 isMimeTypeEqual(new DataFlavor("x/z; param=value", "2")));
+        
+        // Regression for HARMONY-2033
+        assertTrue(new DataFlavor().isMimeTypeEqual(new DataFlavor()));
     }
 
     /*
@@ -386,6 +395,9 @@
                 isMimeTypeEqual("z/y; param=value"));
         assertFalse(new DataFlavor("x/y; class=java.io.Serializable", "1").
                 isMimeTypeEqual("x/z; param=value"));
+        
+        // Regression for HARMONY-2033
+        assertFalse(new DataFlavor().isMimeTypeEqual("")); //$NON-NLS-1$
     }
 
     /*
@@ -420,6 +432,11 @@
                 new DataFlavor("text/xml; class=java.lang.String; charset=US-ASCII", ""),
                 new DataFlavor("text/xml; class=java.lang.String; charset=UTF-16", "")
         }), new DataFlavor("text/xml; class=java.lang.String; charset=UTF-16", ""));
+        
+        
+        // Regression for HARMONY-2033
+        assertNull(DataFlavor
+                .selectBestTextFlavor(new DataFlavor[] { new DataFlavor() }));
     }
 
     @SuppressWarnings("deprecation")



Mime
View raw message