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

Encoding Colors and Fonts in Applets with XMLEncoder throws Exceptions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.4.2
    • Fix Version/s: 6
    • Component/s: client-libs
    • Labels:

      Description



      Name: gm110360 Date: 12/11/2003


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

      FULL OS VERSION :
      Linux bern 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 unknown


      A DESCRIPTION OF THE PROBLEM :
      Encoding Colors and Fonts in Applets with XMLEncoder throws Exceptions (both, either using appletviewer or java-plugin).
      These exceptions are not thrown using a JFrame or in non-gui apps!!!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to encode a Color or a Font with XMLEncoder inside an Applet.

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


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Color0);
              at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:339)
              at java.beans.XMLEncoder.writeObject(XMLEncoder.java:253)
              at test.XMLEncoderTestPanel.encode(XMLEncoderTestPanel.java:60)
              at test.XMLEncoderTestApplet.init(XMLEncoderTestApplet.java:37)
              at sun.applet.AppletPanel.run(AppletPanel.java:347)
              at java.lang.Thread.run(Thread.java:536)
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Font0);
              at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:339)
              at java.beans.XMLEncoder.writeObject(XMLEncoder.java:253)
              at test.XMLEncoderTestPanel.encode(XMLEncoderTestPanel.java:61)
              at test.XMLEncoderTestApplet.init(XMLEncoderTestApplet.java:37)
              at sun.applet.AppletPanel.run(AppletPanel.java:347)
              at java.lang.Thread.run(Thread.java:536)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Class XMLEncoderTestApplet:


      import java.awt.*;
      import javax.swing.*;

      public class XMLEncoderTestApplet extends JApplet {
        
        public XMLEncoderTestApplet() {
        }

        public void init() {
          super.init();
          XMLEncoderTestPanel panel = new XMLEncoderTestPanel();
          getContentPane().add(BorderLayout.CENTER, panel);
          panel.encode();
        }
        
      }



      Class XMLEncoderTestFrame:


      import java.awt.*;
      import javax.swing.*;

      public class XMLEncoderTestFrame extends JFrame {
        
        public XMLEncoderTestFrame() {
          initComponents();
          XMLEncoderTestPanel panel = new XMLEncoderTestPanel();
          getContentPane().add(BorderLayout.CENTER, panel);
          panel.encode();
          pack();
        }
        
        private void initComponents() {
          
          addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
              exitForm(evt);
            }
          });
          
          pack();
        }
        
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
          System.exit(0);
        }
        
        public static void main(String args[]) {
          new XMLEncoderTestFrame().show();
        }
        
      }



      Class XMLEncoderTestPanel:


      import java.awt.Color;
      import java.awt.Font;
      import java.beans.*;
      import java.io.*;
      import java.util.*;
      import javax.swing.*;


      public class XMLEncoderTestPanel extends JPanel {
        
        public XMLEncoderTestPanel() {
          initComponents();
        }

        private void initComponents() {
          jScrollPane1 = new javax.swing.JScrollPane();
          jTextArea1 = new javax.swing.JTextArea();

          setLayout(new java.awt.BorderLayout());

          jTextArea1.setEditable(false);
          jScrollPane1.setViewportView(jTextArea1);

          add(jScrollPane1, java.awt.BorderLayout.CENTER);

        }
        
        public void encode() {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          BufferedOutputStream bos = new BufferedOutputStream(baos);
          XMLEncoder encoder = new XMLEncoder(bos);
          encoder.setExceptionListener(new ExceptionListener(){
            public void exceptionThrown(Exception ex){
              ex.printStackTrace();
            }
          });
          try{
            encoder.writeObject(Color.RED);
            encoder.writeObject(new Font("Arial", 0, 20));
            encoder.flush();
            jTextArea1.setText(baos.toString());
          } catch(Exception ex1){
            ex1.printStackTrace();
          } finally {
            encoder.close();
          }
        }
        
        
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        // End of variables declaration
        
      }



      XMLEncoderTestApplet.html:


      <HTML>
      <HEAD>
         <TITLE>Applet HTML Page</title>
      </head>
      <BODY>

      <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></h3>

      <P>
      <APPLET code="XMLEncoderTestApplet.class" width=350 height=200></applet>
      </p>

      <HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</i></font>
      </body>
      </html>



      ---------- END SOURCE ----------
      (Incident Review ID: 183149)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kereminsunw Konstantin Eremin (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: