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

javac should not warn about missing serialVersionUID for anonymous inner classes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8
    • tools
    • b116
    • generic
    • generic
    • Verified

      Javac issues a [serial] warning if an instantiation of an anonymous inner class is missing a serialVersionUID. For example,

          return new java.security.Key() {
              // ...
          }

      results in something like

          Warning.java:16: warning: [serial] serializable class
          <anonymous Warning$1> has no definition of serialVersionUID

      There are a variety of reasons that serialization compatibility of an anonymous inner class cannot be guaranteed, or even that such instances can be serialized at all. Thus, it is incorrect to warn the user to add a useless serialVersionUID.

      (Reasons include: anonymous class names are implementation-specific and may vary from one build to the next; synthesized field names and types may also vary unpredictably; the enclosing instance or captured local variables might not be serializable; even if they were serializable it's unlikely that this is what the programmer would want.)

            alundblad Andreas Lundblad (Inactive)
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: