Skip to content

@SerialVersionUID is silently ignored if not provided as long literal #6988

Closed
@scabug

Description

@scabug

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions