JDK-6197072 : JCK: Font(Map)/getFont(Map): unexpected exception for attributes of no proper type
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: solaris
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-11-18
  • Updated: 2011-03-29
  • Resolved: 2005-04-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b33Fixed
Related Reports
Relates :  
Relates :  
Description
The spec of TextAttribute states: "If the value is null or not of the proper type then it has the default effect." 
However, trying to instantiate Font with Map containing attribute with value of unproper type throws exception. See code below for problem illustration.
===================== Test65.java ==========================
import java.awt.*;
import java.util.*;
import java.awt.font.*;

public class Test65 {
    public static void main(String[] args) {
        Object o1 = TextAttribute.FAMILY;
        Object o2 = Color.black;
 
        System.out.println("Trying to instantiate font with Map " +
                    "containing incorrect attribute: "
                    + o1 + " = " + o2);

        Map hash = new HashMap(1);
        hash.put(o1, o2);

        Font font = new Font(hash);

        System.out.println("Trying to call getFont(Map) with Map " +
                    "containing incorrect attribute: "
                    + o1 + " = " + o2);

        font = Font.getFont(hash);
        System.out.println("Done");

    }
}
================= output =======================
> java -version 
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b11)
Java HotSpot(TM) Server VM (build 1.6.0-ea-b11, mixed mode)

> java -cp ~/work/test/ Test65
Trying to instantiate font with Map containing incorrect attribute: java.awt.font.TextAttribute(family) = java.awt.Color[r=0,g=0,b=0]
Exception in thread "main" java.lang.ClassCastException: java.awt.Color cannot be cast to java.lang.String
        at java.awt.Font.initFromMap(Font.java:546)
        at java.awt.Font.<init>(Font.java:531)
        at Test65.main(Test65.java:17)

###@###.### 2004-11-18 10:56:27 GMT

Comments
EVALUATION This should be fixed with the putback for 4339577/4296952. ###@###.### 2005-04-14 17:26:40 GMT
14-04-2005