JDK-5088701 : StackOverflowError is thrown when reading RTF document
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-08-18
  • Updated: 2005-02-03
  • Resolved: 2004-11-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u2 b03Fixed 6Fixed
Description
###@###.### 2004-08-18

J2SE Version (please include all output from java -version flag):
  java version "1.5.0-beta3"
  Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b60)
  Java HotSpot(TM) Client VM (build 1.5.0-beta3-b60, mixed mode, sharing)

Does this problem occur on J2SE 1.3.x or 1.4.x?  Yes / No (pick one)
  Yes

Operating System Configuration Information (be specific):
  Win XP

Hardware Configuration Information (be specific):
  P4

Bug Description:
  Stack overflow when parsing RTF document

Steps to Reproduce (be specific):
  When reading attached RTF document, StackOverflowError is thrown.
  Use this sample code to reproduce the error.

import java.io.*;
import javax.swing.text.rtf.RTFEditorKit;
import javax.swing.text.*;

public class RTFConverter {

  public static void main(String[] args) {
    try {
      DefaultStyledDocument doc = new DefaultStyledDocument();
      new RTFEditorKit().read(new FileInputStream("wpt-402010.rtf"), doc, 0);
      String docText = doc.getText(0, doc.getLength());
      System.out.println(docText);
    } catch (Throwable t) {
      //System.err.println(t);
      t.printStackTrace();
    }
  }

}
###@###.### 10/6/04 23:09 GMT

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon mustang
25-09-2004

EVALUATION will work on this bug for the next release ###@###.### 2004-08-19 ==================== RTFReader get confused with the rtf from the bug description. >From the bug's rtf file : {\stylesheet{\lotusoutlinelevel0\fs20 \sbasedon0\snext0 Normal;} The first style in style sheet we have is 0 and it is referencing style 0 RTFREader goes into infinite recursion and thus stack overflow exception. I suggest to check whether the rule references itslef and if it does skip realizing the base style. --- RTFReader.javaFri Oct 22 13:53:25 2004 *************** *** 971,978 **** if (basedOn != STYLENUMBER_NONE) { StyleDefiningDestination styleDest; ! styleDest = (StyleDefiningDestination)definedStyles.get(new Integer(basedOn)); ! if (styleDest != null) { basis = styleDest.realize(); } } --- 971,978 ---- if (basedOn != STYLENUMBER_NONE) { StyleDefiningDestination styleDest; ! styleDest = (StyleDefiningDestination)definedStyles.get(Integer.valueOf(basedOn)); ! if (styleDest != null && styleDest != this) { basis = styleDest.realize(); } } *************** ###@###.### 10/22/04 19:15 GMT
22-10-0004