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

Behavior of java.awt.Font.Font(String ...) has been changed

XMLWordPrintable

    • 2d
    • x86, sparc
    • generic, linux, solaris_2.6



      Name: dsR10051 Date: 11/16/2000


      There is incompatibile change in the behavior of the
      java.awt.Font.Font(String name, int style, int size)
      constructor between JDK1.3 and JDK1.4.
      In JDK1.3 this constructor ignores the bits set in the style parameter
      other than a bitwise union of PLAIN, BOLD and ITALIC and sets the font style
      dependence to this bits, but in JDK1.4 it sets the font style to
      PLAIN if the style argument does not conform to one expected integer bitmasks,
      where expected integer bitmasks are PLAIN, or a bitwise union of BOLD and/or ITALIC.
      The documentation for style parameter of constructor has contradiction in
      the specification of this case:
      "
           ...
           * @param style the style constant for the <code>Font</code>
           * The style argument is an integer bitmask that may
           * be PLAIN, or a bitwise union of BOLD and/or ITALIC
           * (for example, ITALIC or BOLD|ITALIC). Any other
                                                   ^^^^^^^^^
           * bits set in the style parameter are ignored.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (but!!!)
           * If the style argument does not conform to one of the expected
             |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
           * integer bitmasks then the style is set to PLAIN.
             ||||||||||||||||||||||||||||||||||||||||||||||||
           ...
      public Font(String name, int style, int size)
      "

      Here is a minimized test:
      import java.awt.Font;

      public class FontTest02 {

          public static void main(String[] args) {
              int style = Font.BOLD | ~(Font.BOLD | Font.ITALIC);
              Font font = new Font("Dialog", style, 12);
              System.out.println("Font created:");
              System.out.println(font);
              if (font.isBold()) {
                  System.out.println("Font style is bold");
              } else if (font.isPlain()) {
                  System.out.println("Font style is plain");
              } else {
                  System.out.println("FAILED: font style is neither plain nor bold");
              }
              System.exit(0);
          }
      }
      --- Output ---
      %java -version
      java version "1.4.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b40)
      Java HotSpot(TM) Client VM (build 1.4beta-B40, mixed mode)
      %java FontTest02
      Font created:
      java.awt.Font[family=dialog,name=Dialog,style=plain,size=12]
      Font style is plain
      %/set/java/jdk1.3/solaris/bin/java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)
      %/set/java/jdk1.3/solaris/bin/java FontTest02
      Font created:
      java.awt.Font[family=Arial,name=Dialog,style=bold,size=12]
      Font style is bold
      --- ---

      ======================================================================

            pkejriwasunw Parry Kejriwal (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: