harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r785760 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/ test/api/java.injected/javax/swing/text/
Date Wed, 17 Jun 2009 19:15:39 GMT
Author: hindessm
Date: Wed Jun 17 19:15:38 2009
New Revision: 785760

URL: http://svn.apache.org/viewvc?rev=785760&view=rev
Log:
Applied patches from "[#HARMONY-1767] [classlib][swing]
javax.swing.text.ComponentView(Element) throws unexpected NullPointerException
on user's implementation".

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/ComponentView.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/ComponentViewTest.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/StyleConstantsTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/ComponentView.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/ComponentView.java?rev=785760&r1=785759&r2=785760&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/ComponentView.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/ComponentView.java
Wed Jun 17 19:15:38 2009
@@ -182,7 +182,8 @@
     }
 
     protected Component createComponent() {
-        return StyleConstants.getComponent(getAttributes());
+        final AttributeSet attrs = getAttributes();
+        return attrs == null ? null : StyleConstants.getComponent(attrs);
     }
 
     private void isAxisValid(final int axis) {

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/ComponentViewTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/ComponentViewTest.java?rev=785760&r1=785759&r2=785760&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/ComponentViewTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/ComponentViewTest.java
Wed Jun 17 19:15:38 2009
@@ -33,6 +33,10 @@
 import javax.swing.JTextArea;
 import javax.swing.JTextPane;
 import javax.swing.SwingTestCase;
+import javax.swing.text.Element;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.PlainView;
+
 
 public class ComponentViewTest extends SwingTestCase {
     StyledDocument document;
@@ -649,6 +653,47 @@
         }
     }
 
+    public void testSetParent_View() {
+        // Regression test for HARMONY-1767 
+        PlainDocument doc = new PlainDocument();
+        Element e = doc.getDefaultRootElement();
+        ComponentView obj = new ComponentView(new TestElement());
+        obj.setParent(new PlainView(e));
+    }  
+
+    private static class TestElement implements Element {
+        public boolean isLeaf() {
+            return false;
+        }
+        public Element getElement(int index) {
+            return null;
+        }
+        public int getElementCount() {
+            return 0;
+        }
+        public int getElementIndex(int offset) {
+            return 0;
+        }
+        public int getEndOffset() {
+            return 0;
+        }       
+        public int getStartOffset() {
+            return 0;
+        }       
+        public AttributeSet getAttributes() {
+            return null;
+        }
+        public String getName() {
+            return "AA";
+        }
+        public Element getParentElement() {
+            return null;
+        }
+        public Document getDocument() {
+            return null;
+        }
+    }
+
     private void checkBounds(final int x, final int y, final int height, final Shape box)
{
         Rectangle bounds = box.getBounds();
         assertEquals(x, bounds.x);
@@ -688,4 +733,4 @@
             assertEquals(position, componentElement.getStartOffset());
         }
     }
-}
\ No newline at end of file
+}

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/StyleConstantsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/StyleConstantsTest.java?rev=785760&r1=785759&r2=785760&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/StyleConstantsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/StyleConstantsTest.java
Wed Jun 17 19:15:38 2009
@@ -434,6 +434,16 @@
         assertEquals(val, StyleConstants.getComponent(attr));
     }
 
+    public void testGetComponent_Null() {
+        // Regression test for HARMONY-1767
+        try {
+            StyleConstants.getComponent(null);
+            fail("NullPointerException should be thrown");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
     public void testSetComponent() {
         attr.removeAttributes(attr);
         Component val = new JLabel("test component");



Mime
View raw message