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

Out of Memory when loading a 700-800 kB text file

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_95, windows_nt

      Description

      ==========================================================================
      carlos.lucasius@canada 1998-03-19:
      Bug reported by Corel (licensee) for JFC1.1 using JDK1.1.4 on WINNT4.0.
      Corel: "Very critical bug for our product - requires immediate attention."

      Try to load a file of about 800 kB into the JEditorPane. It will take about 5
      minutes on a dual PentinumPro 200 running on NT 4.0. Then you get a "out of
      memory in rendering" message in the DOS box where java.exe is running. It seemed
      that whoever wrote this code is trying to render every line of text out from a
      file instead of just rendering a window fold of text - the way it should be.


      Name: krT82822 Date: 08/16/99


      The html editor kit appears to have a size limitation of circa 32K.

      I was originally using it in an applet and got an StateInvariantError/infinite
       loop exception similar to the error reported in bugs 4128967 and 4116627.
      It can display smaller documents fine, it only occurs when the size goes up.

      If I change to a normal JTextPane instead of an HTMLEditorKit it works fine.

      I have pulled the relevant code out and put it into an application and the
      same thing still happens.

      Here is the application code:


      import java.io.*;
      import java.awt.*;

      import com.sun.java.swing.*;
      import com.sun.java.swing.text.*;
      import com.sun.java.swing.text.html.*;

      public class TestJEditorPane extends JEditorPane
      {
      public static String readFile() throws FileNotFoundException
      {
      System.out.println("inside readFile");
      File f = new File("large.txt");
      FileReader fr = new FileReader(f);
      int ch = 0;
      StringBuffer r = new StringBuffer("");;
      boolean done = false;
      while (ch != -1)
      {
      try
      {
      ch = fr.read();
      r.append((char) ch);
      }
      catch(IOException e)
      {
      done = true;
      }
      }
      System.out.println("returning from readFile");
      return r.toString();
      }

      public TestJEditorPane()
      {
      System.out.println("inside testJEditorPane");
      String str = "";
      try
      {
      str = readFile();
      }
      catch (FileNotFoundException fnfe)
      {
      System.out.println("File not found");
      }

      // String html = "<html><body>hello<img src=mc.jpg></body></html>";
      String html = "<html><body>" + str + "</body></html>";
      System.out.println("html = " + html);
              HTMLEditorKit editorKit = new HTMLEditorKit();
              setEditorKit(editorKit);

              Document document = editorKit.createDefaultDocument();
              try {
      StringReader reader = new StringReader(html);
      editorKit.read(reader, document, 0);
              }
              catch (Throwable t) {
      t.printStackTrace();
      return;
              }
              setDocument(document);
      }

      public static void main(String[] args)
      {
      System.out.println("inside main");
      TestJEditorPane html = new TestJEditorPane();
      html.setEditable(false);
      JScrollPane scroller = new JScrollPane();
      JViewport vp = scroller.getViewport();
      vp.add(html);
      vp.setBackingStoreEnabled(true);

      JFrame f = new JFrame("testing");
      f.getContentPane().setLayout(new BorderLayout());
      f.getContentPane().add("Center", scroller);
      f.pack();
      f.setSize(600, 600);
      f.setVisible(true);
      System.out.println("end of main");
      }
      }
      (Review ID: 42030)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tprinzinsunw Timothy Prinzing (Inactive)
              Reporter:
              clucasius Carlos Lucasius (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: