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

Transient blank final variable cannot be assigned by 'readObject' method

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.3
    • specification
    • None
    • generic, x86
    • generic, windows_95

      The following was reported in the comments for bug 4056774. It is claimed
      that "the readObject method of a Serializable class should be able to make
      assigment to a blank final variable that is also transient", e.g. in the
      example below:

      import java.io.*;

      public class BlankFinal implements java.io.Serializable {
        final Object var1;
        final transient Object var2;

        BlankFinal(Object arg1, Object arg2) {
          var1 = arg1;
          var2 = arg2;
        }

        BlankFinal(Object arg1) {
          this(arg1, arg1);
        }

        private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
          try {
            in.defaultReadObject();
          } catch (NotActiveException nae) {
          }
          var2 = var1;
        }
      }

      The compiler rejects this program, regarding the assignment to 'var2'
      in 'readObject' as a duplicate assignment. This behavior is correct
      according to the inner class specification.

      It appears then that it is impossible to initialize transient blank
      final fields when creating an object from a serialized stream. The
      specification needs to clarify the interaction of 'transient' and 'final',
      and perhaps forbid their combination, at least in the clase of blank finals.

      william.maddox@Eng 1997-08-25

            gbrachasunw Gilad Bracha (Inactive)
            wmaddoxsunw William Maddox (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: