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

javax.naming.CannotProceedException can not be serialized

XMLWordPrintable



      Name: ooR10001 Date: 04/17/2000


      If method setAltNameCtx() is invoked with a non-Serializable parameter,
      the object is no longer serializable.
      For example, it could be invoked with instance of javax.naming.InitialContext.
      In this case object's field 'altNameCtx' will be initialized with
      non-Serializable class instance of javax.naming.Context. This causes the
      problem.
       
      The test example to reproduce the bug:
      -------------------------------------------------------------
      import java.io.FileOutputStream;
      import java.io.ObjectOutputStream;

      public class test {

        public static void main(String[] args) {
          try {
              javax.naming.CannotProceedException obj =
                  new javax.naming.CannotProceedException();
              obj.setAltNameCtx(new javax.naming.InitialContext());

              FileOutputStream ostream = new FileOutputStream("gold.tmp");
              ObjectOutputStream objos = new ObjectOutputStream(ostream);
              objos.writeObject(obj);
              objos.close();

          } catch (java.io.IOException e) {
              e.printStackTrace();
          } catch (javax.naming.NamingException e) {
          }
        }

      }
      -------------------------------------------------------------
      Test output:

      java.io.NotSerializableException: javax.naming.InitialContext
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at
      java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841)
              at
      java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480)
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at test.main(test.java:14)
      -------------------------------------------------------------

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

            rleesunw Rosanna Lee (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: