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

SuppressWarning("serial") ignored on field serialVersionUID

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 17
    • 9
    • tools
    • None
    • b03

    Description

      It should be possible to suppress serial warnings that are specific to a particular declaration such as a method or field.
      Suppressing warnings for the whole class will obscure multiple warnings.

      One specific example is:

      % javac -Xlint A.java

      A.java:10: warning: [serial] serialVersionUID must be of type long in class B
          private static final byte serialVersionUID = 5;
                                    ^
      1 warning
      %

      This warning can only be suppressed at the class level and adding suppress warning("serial") on the field is ignored.

      A.java:

      import java.io.Serializable;

      @SuppressWarnings("serial") // Testing incorrect type of serialVersionUID
      class A implements Serializable {
          private static final byte serialVersionUID = 5;
      }

      class B implements Serializable {
          @SuppressWarnings("serial") // Testing incorrect type of serialVersionUID
          private static final byte serialVersionUID = 5;
      }


      ---
      % java -version
      java version "9"
      Java(TM) SE Runtime Environment (build 9+181)
      Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

      Attachments

        Issue Links

          Activity

            People

              jjg Jonathan Gibbons
              rriggs Roger Riggs
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: