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

LTP: Stack overflow encoding a derived Font with XMLEncoder

XMLWordPrintable

    • b07
    • x86
    • linux, windows_xp
    • Verified

      Name: jl125535 Date: 11/10/2003


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Encoding a font created using the deriveFont(float size) method from an existing font fails with a stack overflow exception. Encoding the original font or an apparently identical font created directly works. The problem seems to occur when the size of the derived font is not an integer.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached example. If the derived size (20.1f) is replaced with an integer value, the problem does not occur.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.4.2" class="java.beans.XMLDecoder">
       <object class="java.awt.Font">
        <string>dialog</string>
        <int>0</int>
        <int>20</int>
       </object>
      </java>

      ACTUAL -
      See stack trace below.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.StackOverflowError
      at java.lang.Exception.<init>(Exception.java:77)
      at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:54)
      at sun.reflect.GeneratedConstructorAccessor1.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
      at java.beans.Statement.invoke(Statement.java:473)
      at java.beans.Expression.getValue(Expression.java:101)
      at java.beans.Encoder.getValue(Encoder.java:84)
      at java.beans.Encoder.get(Encoder.java:186)
      at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:97)

      <The following lines of the stack trace repeat ad infinitum>
              at java.beans.Encoder.writeObject(Encoder.java:55)
              at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
              at java.beans.Encoder.writeExpression(Encoder.java:260)
              at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363)
              at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:1
      00)
      etc

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Font;
      import java.beans.XMLEncoder;
      import java.io.BufferedOutputStream;
      import java.io.FileDescriptor;
      import java.io.FileOutputStream;

      public class TestXMLEncoder
      {
      public static void main(String[] args)
      {
      Font f = new Font("dialog", 0, 20);
      f = f.deriveFont(20.1f);
      XMLEncoder encoder =
                  new XMLEncoder(new BufferedOutputStream(
      new FileOutputStream(FileDescriptor.out)));
      encoder.writeObject(f);
      encoder.close();
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Ensure fonts have integer sizes.
      (Incident Review ID: 194149)
      ======================================================================

            malenkov Sergey Malenkov (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: