harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r466074 - in /incubator/harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/Font.java test/api/java/common/java/awt/FontTest.java
Date Fri, 20 Oct 2006 11:42:43 GMT
Author: mloenko
Date: Fri Oct 20 04:42:42 2006
New Revision: 466074

URL: http://svn.apache.org/viewvc?view=rev&rev=466074
Log:
minor fixes for Font:
HARMONY-1543: awt.Font.getFamily(Locale) with null Locale returns family on Harmony and throws
NPE on RI
HARMONY-1546: java.awt.Font.getFont() with null system property parameter throws NPE on RI
while doesn't on Harmony.
HARMONY-1549: java.awt.Font.getMaxCharBounds() with null FontRenderContext returns bounds
on Harmony and throws NPE on RI

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java?view=diff&rev=466074&r1=466073&r2=466074
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
Fri Oct 20 04:42:42 2006
@@ -561,7 +561,12 @@
 
 
     public String getFamily(Locale l) {
-        FontPeerImpl peer = (FontPeerImpl)this.getPeer();
+        if (l == null) {
+            throw new NullPointerException(Messages.getString(
+                    "awt.01", "Locale")); //$NON-NLS-1$ 
+        }
+
+        FontPeerImpl peer = (FontPeerImpl) this.getPeer();
         return peer.getFamily(l);
     }
 
@@ -575,12 +580,8 @@
     }
 
     public static Font getFont(String sp, Font f) {
-        String pr = null;
-        try {
-            pr = System.getProperty(sp);
-        } catch (Exception e){
-        }
-        if (pr == null){
+        String pr = System.getProperty(sp);
+        if (pr == null) {
             return f;
         }
         return decode(pr);
@@ -601,14 +602,13 @@
         return peer.getFontName(l);
     }
 
-    public LineMetrics getLineMetrics(char[] chars, int start,
-            int end, FontRenderContext frc) {
-
-        if (frc == null){
+    public LineMetrics getLineMetrics(char[] chars, int start, int end,
+            FontRenderContext frc) {
+        if (frc == null) {
             throw new NullPointerException(Messages.getString("awt.00")); //$NON-NLS-1$
         }
 
-        FontPeerImpl peer = (FontPeerImpl)this.getPeer();
+        FontPeerImpl peer = (FontPeerImpl) this.getPeer();
 
         return peer.getLineMetrics((new String(chars)).substring(start, end),
                 frc, this.getTransform());
@@ -752,6 +752,10 @@
     }
 
     public Rectangle2D getMaxCharBounds(FontRenderContext frc) {
+        if (frc == null){
+            throw new NullPointerException(Messages.getString("awt.00")); //$NON-NLS-1$ 
+        }
+
         FontPeerImpl peer = (FontPeerImpl)this.getPeer();
 
         Rectangle2D bounds = peer.getMaxCharBounds(frc);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java?view=diff&rev=466074&r1=466073&r2=466074
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
Fri Oct 20 04:42:42 2006
@@ -19,51 +19,94 @@
 
 import java.awt.font.TextAttribute;
 import java.text.AttributedString;
+import java.util.Collections;
+import java.util.Map;
 
 import junit.framework.TestCase;
 
 public class FontTest extends TestCase {
 
     private final Font f = new Font("dialog", Font.PLAIN, 12);
-    
+
     /**
-     * Checks Font.getLineMetrics() methods if FontRenderContext parameter is NULL. 
-     *
+     * Checks Font.getLineMetrics() methods if FontRenderContext parameter is
+     * NULL.
+     * 
      */
-    public void test_Font_getLineMetrics_WithNullFRC(){
-        // // regression test for Harmony-1465
+    public void test_Font_getLineMetrics_WithNullFRC() {
+        // Regression for Harmony-1465
         final String str = "test";
-        try{
+        try {
             f.getLineMetrics(str, null);
             fail("NullPointerException expected but wasn't thrown!");
-        }catch (NullPointerException e) {
+        } catch (NullPointerException e) {
             // as expected
         }
 
-        try{
+        try {
             f.getLineMetrics(str, 1, 3, null);
             fail("NullPointerException expected but wasn't thrown!");
-        }catch (NullPointerException e) {
+        } catch (NullPointerException e) {
             // as expected
         }
 
-        try{
+        try {
             f.getLineMetrics(str.toCharArray(), 1, 3, null);
             fail("NullPointerException expected but wasn't thrown!");
-        }catch (NullPointerException e) {
+        } catch (NullPointerException e) {
             // as expected
         }
 
-        try{
+        try {
             AttributedString as = new AttributedString("test");
-            as.addAttribute(TextAttribute.FONT, f, 0, 2 );
+            as.addAttribute(TextAttribute.FONT, f, 0, 2);
 
             f.getLineMetrics(as.getIterator(), 1, 3, null);
             fail("NullPointerException expected but wasn't thrown!");
-        }catch (NullPointerException e) {
+        } catch (NullPointerException e) {
             // as expected
         }
-        
     }
-    
+
+    public void test_Font_getMaxCharBounds_WithNullFRC() {
+        // Regression for HARMONY-1549
+        try {
+            Font font = Font.decode("dialog");
+            System.out.println(font.getMaxCharBounds(null));
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+    }
+
+    public void test_Font_getFamily_WithNullLocale() {
+        // Regression for Harmony-1543
+        try {
+            Font fnt = Font
+                    .getFont((Map<? extends TextAttribute, ?>) Collections.EMPTY_MAP);
+            fnt.getFamily(null);
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void test_Font_getFont_WithNullSystemProperty() {
+        // Regression for HARMONY-1546
+        try {
+            Font.getFont((String) null);
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            Font.getFont((String) null, new Font("dialog", Font.PLAIN, 12));
+            fail("NullPointerException expected!");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+    }
 }



Mime
View raw message