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

Make AbstractAction.ArrayTables serializable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • None
    • beta
    • generic
    • generic

      Date: 04 Jun 1999 08:06:03 -0700
      From: "Scott Violet" <###@###.###>
      Subject: Re: Serializing ArrayTables
      To: "Georges Saab" <###@###.###>
      Cc: ###@###.###

      Georges Saab <###@###.###> writes:
      > I noticed that you (and I) are both serializing ArrayTables
      > by hand. It occurs to me that perhaps we should move the
      > serialization code for these into ArrayTable itself and then
      > just not declare the fields transient.
      >
      > What do you think?

      Pro: we don't have to duplicate serialization code.
      Con: we are locked down to the ArrayTable implementation.

      When I had talked to Hans about this (when doing InputMap/ActionMap)
      he thought the con outweighted the pro, which is why InputMap/ActionMap
      have the exact same code in it for serializing the ArrayTable.
      Perhaps we could add a package private method to ArrayTable that does
      the serializing/unserializing (not readObject/writeObject), that way
      we aren't locked into using ArrayTable. I'm thinking something
      like the following:
      public class InputMap ....

          private void writeObject(ObjectOutputStream s) throws IOException {
              ArrayTable.write(s, arrayTable);
          }

          private void readObject(ObjectInputStream s) throws ClassNotFoundException,
      IOException {
              arrayTable = ArrayTable.read(s);
          }

      class ArrayTable ...

          static void write(ObjectOutputStream s, ArrayTable table) {
              if (table == null) {
      s.writeInt(0);
              }
      else {
      int size = table.size();
      Object[] keys = new Object[table.size()];
      table.getKeys(keys);
      int validCount = 0;
      for (int counter = 0; counter < size; counter++) {
      if ((keys[counter] instanceof Serializable) &&
      (table.get(keys[counter]) instanceof Serializable)) {
      validCount++;
      }
      else {
      keys[counter] = null;
      }
      }
      s.writeInt(validCount);
      for (int counter = 0, gCount = 0; counter < size; counter++) {
      if (keys[counter] != null) {
      s.writeObject(keys[counter]);
      s.writeObject(table.get(keys[counter]));
      if (++gCount == validCount) {
      break;
      }
      }
      }
      }
          }

      Notice the handling of null. If InputMap.read was invoked, and their
      was no valid entries (readInt() == 0) I would say it should return
      null.
      Additionaly we could make the methods that call write on ArrayTable
      write and int, or string, indicating that ArrayTable is being
      used. That way, if we decide not to use ArrayTables in the future we
      have a way of knowing it is a serialized ArrayTable.

      What do you think?

      -Scott

            svioletsunw Scott Violet (Inactive)
            gsaab Georges Saab
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: