Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6270677

Font.getFont(String) incorrectly returns null

    XMLWordPrintable

Details

    • 2d
    • b45
    • x86
    • linux
    • Verified

    Description

      The J2SE 5.0 spec states for Font.getFont(String):
      "Returns a Font object from the system properties list. nm is treated as the name of a system property
       to be obtained. The String value of this property is then interpreted as a Font object according to the
       specification of Font.decode(String) If the specified property is not found, null is returned instead."

      This method may return null if the property is not found, however if the property does exist and
      there is no java.util.PropertyPermission "*", "read" the getFont would still return null. The spec
      for the getFont method does not require this permission to function properly, so the implementaion
      does not follow the spec. Actually, it seems to be a specification issue. Since the method explicitly
      mentions the system properties list then it is necessary to describe behavior in the constraint
      environment: throws SecurityException or explicitly specify null return value for no permission case.

      The follow sample code demonstrates incorrect behavior:
      ----------------- TestFont.java ---------------
      import java.awt.Font;

      public class TestFont {

          public static void main(String[] args) {
              new TestFont().test();
          }


          private void test() {
              String name = "NewFont";

              System.setProperty(name, "BoldFont-bolditalic-10");
              System.out.println(Font.getFont(name));
          }
      }
      ---------------------------------------------------
      --------------- test.polcy ------------------------
      grant{
      // permission java.util.PropertyPermission "*", "read";
        permission java.util.PropertyPermission "*", "write";
      };
      ---------------------------------------------------
      #java -version
      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
      Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
      #java -Djava.security.manager -Djava.security.policy==test.policy -cp . TestFont
      null

      ###@###.### 2005-05-16 05:50:02 GMT

      Attachments

        Activity

          People

            prr Philip Race
            visaenko Vasily Isaenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: