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

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

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.1.3
    • Fix Version/s: None
    • Component/s: specification
    • Labels:
      None
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, windows_95

      Description

      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: