harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r495692 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/JEditorPane.java test/api/java/common/javax/swing/JEditorPaneTest.java
Date Fri, 12 Jan 2007 19:26:58 GMT
Author: hindessm
Date: Fri Jan 12 11:26:57 2007
New Revision: 495692

URL: http://svn.apache.org/viewvc?view=rev&rev=495692
Log:
Applied patch from "[#HARMONY-2031] [classlib][swing] JEditorPane
setContentType(String), setPage(String) and setPage(URL) throw wrong
exceptions if parameter is null".

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java?view=diff&rev=495692&r1=495691&r2=495692
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
Fri Jan 12 11:26:57 2007
@@ -552,6 +552,10 @@
      }
      */
     public final void setContentType(final String type) {
+        if (type == null) {
+            throw new NullPointerException("Content type is null");
+        }
+
         if (type == "text/html" || type == "text/rtf") {
             System.err
                     .println("WARNING: HTML/RTF is not supported yet. Plain text will be
shown");
@@ -655,6 +659,10 @@
     }
 
     public void setPage(final URL page) throws IOException {
+        if (page == null) {
+            throw new IOException("Page is null");
+        } 
+
         //temporarily commented-out: HTMLDocument not implemented
         /*
          String url = page.toString();
@@ -722,9 +730,11 @@
     //        }
     //        return -1;
     //    }
+
     @Override
     public synchronized void setText(final String content) {
-        StringReader reader = new StringReader(content);
+        StringReader reader = new StringReader(content == null ? "" : content);
+
         try {
             read(reader, contentType);
         } catch (IOException e) {

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java?view=diff&rev=495692&r1=495691&r2=495692
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java
Fri Jan 12 11:26:57 2007
@@ -324,6 +324,14 @@
         jep.setContentType("text/html");
         jep.setText(htmlString);
         assertEquals(removeMeta(htmlString), removeMeta(jep.getText().replaceAll("\n", "")));
+
+        JEditorPane e = new JEditorPane();
+        
+        try {               
+            e.setText((String) null);  
+        } catch (NullPointerException npe) {            
+            fail("NullPointerException thrown");
+        }
     }
 
     // commented due to unimplemented functionality
@@ -541,6 +549,15 @@
             assertTrue("Unexpected exception :" + e.getMessage(), false);
         }
         //assertEquals(TEST_URL, jep.getPage());
+
+        JEditorPane e = new JEditorPane();
+        
+        try {               
+            e.setPage((java.net.URL) null);
+            fail("IOException must be thrown");
+        } catch (java.io.IOException ioe) {
+            // PASSED
+        }
     }
 
     public void testSetGetPage2() {
@@ -676,6 +693,15 @@
                 .getName());
         assertEquals("javax.swing.text.PlainDocument", getClassName(jep.getDocument()));
         JEditorPane.registerEditorKitForContentType("text/test", "");
+
+        JEditorPane e = new JEditorPane();
+        
+        try {   
+            e.setContentType((String) null);
+            fail("NPE must be thrown");
+        } catch (NullPointerException npe) { 
+            // PASSED           
+        }
     }
 
     private String getClassName(final Object obj) {



Mime
View raw message