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

Font(String name, int style, int size) acsepts invalid style

XMLWordPrintable

    • 2d
    • beta
    • sparc
    • solaris_2.5



      Name: dsC58869 Date: 09/21/98



      The new spec (bugfix #4169077) for java.awt.Font(String name, int style, int size)
      says about style argument:

           * @param style the style constant for the font.
           * 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.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           * If the style argument does not conform to one of the expected
           * integer bitmasks then the style is set to PLAIN.
           *
      ( @(#)Font.java 1.113 98/09/14 )

      But constructor doesn't ignore other bits. It simply sets
      protected int style field to invalid value.


      ==== Here is the test demonstrating the bug ====

      import java.awt.*;

      public class TestFont22 {
          public static void main(String[] args) {
      Font f1 = new Font("", Font.BOLD, 12);
      Font f2 = new Font("", (Font.BOLD | 16), 12);
      System.out.println(f1.toString());
      System.out.println(f2.toString());
      /* Other bits are ignored, equals should return TRUE (by spec) */
      if(f1.equals(f2)) {
      System.out.println("OKAY");
      } else {
      System.out.println("Failed");
      }
          }
      }

      === OUTPUT ===
      %java TestFont22
      java.awt.Font[family=Times,name=,style=bold,size=12]
      java.awt.Font[family=Times,name=,style=bold,size=12]
      Failed
      %

      ======================================================================
       See also:
      4169077, 4160325

       Justification:
      Need to update JCK tests by spec:
         api/java_awt/Font/manual.html#Ctor
         api/java_awt/Font/manual.html#Equals
         api/java_awt/Font/manual.html#IsXXXX
         api/java_awt/Font/manual.html#ToString

       Suggested fix:
      Into constructor Font(String name, int style, int size)
      > this.style = style;
      < this.style = style & (Font.BOLD | Font.ITALIC);

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

            dougfelt Doug Felt (Inactive)
            dsilaev Dmitri Silaev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: