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

java.awt.FontMetrics is incorrectly deserialized in jdk 1.2beta4

XMLWordPrintable

    • 2d
    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: avC70361 Date: 06/11/98



        The java.awt.FontMetrics is incorrectly deserialized under jdk1.2beta4 when
      has been serialized under jdk1.1.6. Their ascent, descent and some other fields
      are different.

        Here is a test demonstrating the bug.
      ----------FontMetricsTest.java--------
      import java.awt.Font;
      import java.awt.Panel;
      import java.awt.FontMetrics;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;

      public class FontMetricsTest {
        public static void main(String[] args) {
          Panel panel = new Panel();
          Font font = new Font("Dialog", Font.PLAIN, 12);
          FontMetrics fm = panel.getFontMetrics(font);

          String fileName = args[1];

          if (args[0].equals("write")) {
            try {
              ObjectOutputStream stream = new ObjectOutputStream(
                new FileOutputStream(fileName)
              );

              stream.writeObject(fm);

              System.out.println("Passed");
            } catch(Exception e) {
              System.out.println("Failed: unexpected exception : " + e);
            }
          } else if (args[0].equals("read")) {
            try {
              ObjectInputStream stream = new ObjectInputStream(
                new FileInputStream(fileName)
              );

              FontMetrics result = (FontMetrics)stream.readObject();

              if (result.getAscent() != fm.getAscent()) {
                System.out.println(
                  "Deserialization failed.\n" +
                   "Deserialized and expected font metrics have different ascent\n" +
                  "deserialized font metrics = " + result + "\n" +
                  "expected font metrics = " + fm
                );
              } else {
                System.out.println("Passed");
              }
            } catch(Exception e) {
              System.out.println("Failed: unexpected exception : " + e);
            }
          }

          System.exit(0);
        }
      }
      ---------The test output--------
      under jdk1.1.6:
      <avv@stardust(pts/3).437> java -version
      java version "1.1.6"
      <avv@stardust(pts/3).438> java FontMetricsTest write file.ser
      Passed
      <avv@stardust(pts/3).439> java FontMetricsTest read file.ser
      Passed

      under jdk1.2beta4:
      <avv@stardust(pts/3).442> java -version
      java version "1.2beta4"
      Classic VM (build JDK-1.2beta4-I, green threads, sunwjit)
      <avv@stardust(pts/3).443> java FontMetricsTest read file.ser
      Deserialization failed.
      Deserialized and expected font metrics have different ascent
      deserialized font metrics = sun.awt.motif.X11FontMetrics[font=java.awt.Font[family=Utopia Regular,name=Dialog,style=plain,size=12]ascent=11, descent=2, height=14]
      expected font metrics = sun.awt.font.FontDesignMetrics[font=java.awt.Font[family=Utopia Regular,name=Dialog,style=plain,size=12]ascent=9, descent=3, height=13]

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

      Related to 4150944

            dfeldsunw Dmitry Feld (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: