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

text.rtf.RTFEditorkit.write(...) throw NPE when used in applet

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: aaC67449 Date: 10/02/98



      text.rtf.RTFEditorkit.write(...) throw NullPointerException when used in applet

      But it works correctly in application.

      For example:
      ----------------- Example ----------------

      ---------Test.java------
      import javax.swing.*;
      import java.io.*;
      import javax.swing.text.*;
      import javax.swing.text.rtf.*;

      public class Test extends JApplet{

         public static void main(String argv[]) {
           (new Test()).init();
         }
         
         public void init() {
             String test="{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\f swiss MS Sans Serif;}}{\\colortbl\\red0\\green0\\blue0;}\\qc\\plain\\f0 Test 1 \\par \\ql\\plain\\f0 Test 2 \\par \\qr\\plain\\f0 Test 3 \\par \\qj\\plain\\f0 Test 4}";
            
            RTFEditorKit c = new RTFEditorKit();
            Document doc=c.createDefaultDocument();
            try {
              c.read(new ByteArrayInputStream(test.getBytes("8859_1")),doc,0);
            
              ByteArrayOutputStream sw=new ByteArrayOutputStream();
              c.write(sw,doc,0,0);
           } catch(Exception e) {
               e.printStackTrace();
           }
       
         }

      }

      ------------- test1.html --------
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.X//EN">
      <html>
        <head>
          <title>Test</title>
        </head>
       
        <body>
            <p> <hr>
            <applet
              code=Test
              codebase="classes"
            >
            </applet>
       
        </body>
      </html>


      --------------- Applet output ------------------
      #>appletviewer http://server:8080/~ali/test1.html
      Enabling platform fonts. NOTE: usePlatformFont is now deprecated and will be removed in the next build.
      reading charset ansi
      Exception loading RTF character set "ansi": java.lang.NullPointerException
      Unknown RTF character set "ansi"
      Unknown keyword: deff (param 0)
      Unknown keyword: deftab (param 720)
      Done reading font table.
      Number 0: swiss MS Sans Serif
       
      Done reading color table, 1 entries.
      RTF filter done.
      reading charset ansi
      java.lang.NullPointerException
              at javax.swing.text.rtf.RTFReader.readCharset(Compiled Code)
              at javax.swing.text.rtf.RTFReader.getCharacterSet(Compiled Code)
              at javax.swing.text.rtf.RTFGenerator.outputConversionForName(Compiled Code)
              at javax.swing.text.rtf.RTFGenerator.writeRTFHeader(Compiled Code)
              at javax.swing.text.rtf.RTFGenerator.writeDocument(Compiled Code)
              at javax.swing.text.rtf.RTFEditorKit.write(Compiled Code)
              at Test.init(Compiled Code)
              at sun.applet.AppletPanel.run(Compiled Code)
              at java.lang.Thread.run(Compiled Code)
      ^C

      ---------------- Application output-------
      #>java Test
      Enabling platform fonts. NOTE: usePlatformFont is now deprecated and will be removed in the next build.
      reading charset ansi
      Unknown keyword: deff (param 0)
      Unknown keyword: deftab (param 720)
      Done reading font table.
      Number 0: swiss MS Sans Serif
       
      Done reading color table, 1 entries.
      RTF filter done.


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

        Attachments

          Activity

            People

            Assignee:
            svioletsunw Scott Violet (Inactive)
            Reporter:
            aalievsunw Artem Aliev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: