Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4770950
Votes 0
Synopsis A bug of javax.swing.JTextField
Category java:classes_swing
Reported Against 1.4.1 , 1.3.1_08 , merlin-beta2
Release Fixed 1.4.2(mantis)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 4513615 , 4771604
Submit Date 30-OCT-2002
Description
In using javax.swing.JTextField, it throws java.io.NotSerializableException
if a given parameter is a String of Japanese characters (non-ascii characters)
and try to serialize.  JTextField implements Serializable, and when the string
consists of ascii characters, no exception is thrown.

The following code is the sample code showing this synopsis.  Line 6 causes
the exception when the parameter given to the constructor is a String of
Japanese characters (though Japanese characters cannot be shown correctly
in this text field).



     1  import java.io.*;
     2  import javax.swing.*;
     3
     4  public class Test {
     5     public static void main(String[] args)throws Exception {
     6        JTextField ta = new JTextField("Ƚ");
     7        ObjectOutputStream out = new ObjectOutputStream(System.out);
     8        out.writeObject(ta);
     9        out.close();
    10     }
    11  }



% java Test > tmpfile
Exception in thread "main" java.io.NotSerializableException: java.lang.Object
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
        at java.util.Hashtable.writeObject(Hashtable.java:801)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:795)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1294)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1330)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1302)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1330)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1302)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
        at Test.main(Test.java:8)
Work Around
N/A
Evaluation





AbstractDocument.MultiByteProperty is an Object. When character > 255 is to
be shown in the text component MultiByteProperty is stored in the attributes
hashtable.

Object is not serializable thus that hashtable not serializable thus text
component not serializable.

The only thing we need from that property is uniqueness. We might use any
serializable object instead of Object. String will do for example


------- AbstractDocument.java -------
1566c1566
<     static final Object MultiByteProperty = new Object();
---
>     static final Object MultiByteProperty = new String();




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

<     static final Object MultiByteProperty = new Object();
---
>     static final Object MultiByteProperty = "multiByte";

 xxxxx@xxxxx  2004-09-21
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang