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

Some methods return null for AttributeSet

XMLWordPrintable

    • 2d
    • 1.2beta4
    • generic, x86
    • generic, windows_95
    • Not verified

      Some methods return null for AttributeSet

      Following methods return null. They should return empty AttributeSet
      objects if there actually is no attribute.

      java.awt.Font#getAttributes() for Font.DEFAULT
      java.awt.Font#getRequestedAttributes() for Font.DEFAULT
      java.awt.font.StyledString#getAttributes(0) for StyledString

      Problem on Windows 95 as well as Solaris environment.

      Compile and run the attached test case.

      -----------------------------------------------------------------------------

      import java.awt.Font;
      import java.awt.font.StyledString;
      import java.text.AttributeSet;

      class test
      {
      public static void main( String args[] )
      {
      AttributeSet as;

                      as = Font.DEFAULT.getAttributes();
      if ( as != null )
      System.out.println( "Passed for Font#getAttributes." );
      else
      System.out.println( "Failed for Font#getAttributes." );

      as = Font.DEFAULT.getRequestedAttributes();
      if ( as != null )
      System.out.println( "Passed for Font#getRequestedAttributes." );
      else
      System.out.println( "Failed for Font#getRequestedAttributes." );

                      StyledString ss = new StyledString( "StyledString", Font.DEFAULT );
                      as = ss.getAttributes( 0 );

      if ( as != null )
      System.out.println( "Passed for StyledString#getAttributes." );
      else
      System.out.println( "Failed for StyledString#getAttributes." );
      }
      }


      ronan.mandel@Eng 1997-12-23
      /*
        Bug report from Scott Hudson <###@###.###>
        This bug manifests itself under JDK 1.2beta2 running on Win 95.

        The applet below causes the appletviewer to crash. In the "illegal
        operation" dialog that comes up I get the following trace information:

          APPLETVIEWER caused an invalid page fault in
          module KERNEL32.DLL at 013f:bff9a5d0.
          Registers:
          EAX=c0015164 CS=013f EIP=bff9a5d0 EFLGS=00010216
          EBX=0238ff84 SS=0147 ESP=0228feb4 EBP=02290150
          ECX=00000000 DS=0147 ESI=0087a520 FS=10df
          EDX=00000000 ES=0147 EDI=78035b90 GS=0000
          Bytes at CS:EIP:
          53 8b 15 7c c2 fb bf 56 89 4d e4 57 89 4d dc 89
          Stack dump:

        There appears to be two bugs here. First the font found in Font.DEFAULT
        looks to be bogus, and second, passing that font to Graphics.setFont()
        seems to cause a crash. If you comment out the line that actually crashes,
        then you get a NullPointerException when using it later on.
      */

      import java.awt.*;
      import java.applet.Applet;

      public class bug_report2 extends Applet {
        public void paint(Graphics gc)
          {
            Dimension sz = getSize();
            Font fnt = Font.DEFAULT;

            // fnt appears bogus when printed here
            System.err.println("fnt = " + fnt);

            System.err.println("Point 1");
            gc.clearRect(0,0, sz.width, sz.height);
            System.err.println("Point 2");

            // crash seems to be here...
            gc.setFont(fnt);

            System.err.println("Point 3");
            gc.drawString("CANCEL",10,10);
            System.err.println("Point 4");
            FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(fnt);
            System.err.println("Point 5");
            int w = metrics.stringWidth("CANCEL");
            System.err.println("Point 6");
            int h = metrics.getAscent() + metrics.getDescent();
            System.err.println("Point 7");
            gc.drawRect(10,10,w,h);
            System.err.println("Point 8");
          }
       }

            pcharltosunw Paul Charlton (Inactive)
            msonbellsunw Mark Son-bell (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: