Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-6988

@SerialVersionUID is silently ignored if not provided as long literal

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.2, Scala 2.10.0
    • Fix Version/s: Scala 2.11.1
    • Component/s: None
    • Environment:

      Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_11).

      Description

      It seems that if you provide serial version UID to the annotation as anything else rather than long literal scala compiler just silently ignores its value.

      It should either accept the value or raise an error, failing the compilation.

      case class User()
       
      @SerialVersionUID(13.asInstanceOf[Long]) case class IdentifyMessage1(userName: String, user: User, code: Int)
      @SerialVersionUID(13l) case class IdentifyMessage2(userName: String, user: User, code: Int)
      val SerialUID = "13".toLong
      @SerialVersionUID(SerialUID) case class IdentifyMessage3(userName: String, user: User, code: Int)
       
      println("#1 " + java.io.ObjectStreamClass.lookup(IdentifyMessage1("hei", User(), 8).getClass).getSerialVersionUID)
      println("#2 " + java.io.ObjectStreamClass.lookup(IdentifyMessage2("hei", User(), 8).getClass).getSerialVersionUID)
      println("#3 " + java.io.ObjectStreamClass.lookup(IdentifyMessage3("hei", User(), 8).getClass).getSerialVersionUID)
      
      

      Running this code should print out 13 for all classes, but only #2 is correct.

      #1 -7748233784455101520
      #2 13
      #3 1213360818062299825
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                retronym Jason Zaugg
                Reporter:
                arturaz Artūras Šlajus
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: