JDK-8002086 : javac should warn if serialVersionUID is present in an enum or anon subclass of an enum
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2012-11-01
  • Updated: 2019-05-19
  • Resolved: 2019-05-19
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.
Other
tbd_majorResolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Javac doesn't issue a warning if a serialVersionUID is present in an enum or an anonymous subclass. It should issue a warning, since the serialVersionUID of any enum or anon subclass of enum is defined to be 0L.

Compiling the following with -Xlint:all generates no warnings.

It might be reasonable to have this warning controlled by the "serial" lint option, that is, enabled via -Xlint:serial.

----- Guy.java -----

enum Guy {
    TOM {
        private static final long serialVersionUID = 4290774380558885855L;
    },

    DICK {
        private static final long serialVersionUID = -6849794470754667710L;
    },

    HARRY {
        private static final long serialVersionUID = -9172774392245257468L;
    };

    private static final long serialVersionUID = 1360826667806852920L;
}

Comments
The check on serialVersionUID suggested here will be subsumed in the work described in JDK-8202056. A pass was made of the JDK sources to correct misleading serialVersionUID fields in enum types (JDK-8207751).
19-05-2019