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

Specialized does not propagate SerialVersionUID to specialized subclasses, and ignores it altogether in 2.11 #8574

Closed
scabug opened this issue May 10, 2014 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 10, 2014

2.10:

fukaeri:~ dlwh$ cat x.scala

@SerialVersionUID(1L)
class Foo[@specialized(Int) T](x: Int) extends Serializable


fukaeri:~ dlwh$ javap -private Foo\$mcI\$sp.class
Compiled from "x.scala"
public class Foo$mcI$sp extends Foo<java.lang.Object> {
  private final int x;
  public Foo$mcI$sp(int);
}
fukaeri:~ dlwh$ javap -private Foo.class
Compiled from "x.scala"
public class Foo<T> implements scala.Serializable {
  public static final long serialVersionUID;
  public Foo(int);
}

2.11;

fukaeri:~ dlwh$ javap -private Foo.class
Compiled from "x.scala"
public class Foo implements scala.Serializable {
public final T x;
public T x();
public int x$mcI$sp();
public boolean specInstance$();
public Foo(T);
}
fukaeri:~ dlwh$ javap -private Foo
Foo$mcI$sp.class Foo.class
fukaeri:~ dlwh$ javap -private Foo$mcI$sp.class
Compiled from "x.scala"
public class Foo$mcI$sp extends Foo<java.lang.Object> {
public final int x$mcI$sp;
public int x$mcI$sp();
public int x();
public boolean specInstance$();
public java.lang.Object x();
public Foo$mcI$sp(int);
}

2.11:


fukaeri:~ dlwh$ javap -private Foo\$mcI\$sp.class
Compiled from "x.scala"
public class Foo$mcI$sp extends Foo<java.lang.Object> {
  private final int x;
  public Foo$mcI$sp(int);
}
fukaeri:~ dlwh$ javap -private Foo.class
Compiled from "x.scala"
public class Foo<T> implements scala.Serializable {
  public Foo(int);
}

(also, the "private final int x" should probably not be there...)

@scabug
Copy link
Author

scabug commented May 10, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8574?orig=1
Reporter: @dlwh
Affected Versions: 2.10.4, 2.11.0
See #8549

@scabug
Copy link
Author

scabug commented May 10, 2014

@dlwh said:
The 2.11 issue is a dup of #8549.

@scabug
Copy link
Author

scabug commented May 10, 2014

@retronym said:
We are about to cut 2.11.1 to address #8549, the regression in the SerialVersionUID annotation.

I actually read recently that Java would look up the base class list for a static serialVersionUID field. But I hadn't verified this.

Seems not to work in this case:

scala> import annotation._
import annotation._

scala> @SerialVersionUID(42) class Foo[@specialized(Int) T] extends Serializable
defined class Foo

scala> val fooInt = new Foo[Int]().getClass
fooInt: Class[_ <: Foo[Int]] = class Foo$mcI$sp

scala> java.io.ObjectStreamClass.lookup(fooInt).getSerialVersionUID
res0: Long = 569518787336291384

scala> java.io.ObjectStreamClass.lookup(new Foo[String]().getClass).getSerialVersionUID
res1: Long = 42

@scabug
Copy link
Author

scabug commented May 10, 2014

@retronym said:
scala/scala#3738

@scabug
Copy link
Author

scabug commented May 10, 2014

@dlwh said:
Thanks for getting to it so quickly! Yeah, I also had thought that Java was supposed to look at the base class... but I lost the results of a 24-hour experiment to it. So... :-)

@scabug scabug closed this as completed May 17, 2014
@scabug scabug added this to the 2.11.1 milestone Apr 7, 2017
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