harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r488295 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/Font.java test/api/java/common/java/awt/FontTest.java
Date Mon, 18 Dec 2006 15:02:15 GMT
Author: apetrenko
Date: Mon Dec 18 07:02:15 2006
New Revision: 488295

URL: http://svn.apache.org/viewvc?view=rev&rev=488295
Log:
Patch for HARMONY-1595 "[classlib][awt]Compatibility: java.awt.Font.getStringBounds() methods
for null FontRenderContext returns bounds on Harmony and throws NPE on RI"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java?view=diff&rev=488295&r1=488294&r2=488295
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java Mon
Dec 18 07:02:15 2006
@@ -681,6 +681,10 @@
                     (end - start)));
         }
 
+        if (frc == null) {
+            throw new NullPointerException(Messages.getString("awt.00")); //$NON-NLS-1$
+        }
+
         chars = new char[end - start];
 
         ci.setIndex(start);
@@ -719,6 +723,10 @@
             // awt.97=Wrong range length: {0}
             throw new IndexOutOfBoundsException(Messages.getString("awt.97", //$NON-NLS-1$
                     (end - start)));
+        }
+
+        if (frc == null) {
+            throw new NullPointerException(Messages.getString("awt.00")); //$NON-NLS-1$
         }
 
         FontPeerImpl peer = (FontPeerImpl) this.getPeer();

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java?view=diff&rev=488295&r1=488294&r2=488295
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
Mon Dec 18 07:02:15 2006
@@ -21,6 +21,7 @@
 import java.awt.font.TextAttribute;
 import java.text.AttributedString;
 import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
 import java.text.AttributedCharacterIterator.Attribute;
 import java.util.Collections;
 
@@ -142,4 +143,44 @@
             // expected
         }
     }
+    
+    /**
+     * Checks Font.getStringBounds() methods if FontRenderContext parameter is NULL. 
+     *
+     */
+    public void test_Font_getStringBounds_WithNullFRC() {
+        // regression test for Harmony-1595
+        Font font = Font.decode("Arial");
+        try {
+            font.getStringBounds(new char[] { 'a' }, 0, 1,
+                    (FontRenderContext) null);
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            font.getStringBounds(new StringCharacterIterator("a"), 0, 1,
+                    (FontRenderContext) null);
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        String str = "str";
+        try {
+            font.getStringBounds(str, 0, 1, (FontRenderContext) null);
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            font.getStringBounds(str, (FontRenderContext) null);
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
 }



Mime
View raw message