Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scabug opened this issue Jan 18, 2013 · 3 comments
Closed

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

scabug opened this issue Jan 18, 2013 · 3 comments

Comments

@scabug
Copy link

scabug commented Jan 18, 2013

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
@scabug
Copy link
Author

scabug commented Jan 18, 2013

Imported From: https://issues.scala-lang.org/browse/SI-6988?orig=1
Reporter: Artūras Šlajus (arturaz)
Affected Versions: 2.9.2, 2.10.0
See #8549

@scabug
Copy link
Author

scabug commented Jan 18, 2013

@scabug
Copy link
Author

scabug commented May 5, 2014

@retronym said:
Related:
scala/scala#1673
#8459
scala/scala#3711

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants