JDK-7152104 : javac should not warn about missing serialVersionUID for anonymous inner classes
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-03-08
  • Updated: 2016-04-28
  • Resolved: 2016-04-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b116Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
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.)

Comments
A fix for this may be helpful in cleaning up the serial warnings in the JDK.
29-01-2014

It might be reasonable for javac to issue a warning if a serialVersionUID *is* present on an anonymous inner class. Conceivably somebody might actually be serializing anonymous inner classes, even though we don't guarantee compatibility, we've probably been compatible for several releases. So adding this warning isn't a no-brainer.
01-11-2012