Skip to content

Add missing @serialversionuid on collections#9166

Merged
lrytz merged 1 commit intoscala:2.12.xfrom
regadas:2.12.x_serial_version
Feb 18, 2021
Merged

Add missing @serialversionuid on collections#9166
lrytz merged 1 commit intoscala:2.12.xfrom
regadas:2.12.x_serial_version

Conversation

@regadas
Copy link
Contributor

@regadas regadas commented Aug 12, 2020

Hi 👋

I recently stumbled upon scala/bug#5046 while trying to run some scala jobs on Flink. I see that this made it to 2.13 but Flink still runs 2.11/2.12 and per @SethTisue comment I backported some of the changes.

Also, per @lrytz scala/collection-strawman#418 i thought I could set the new @SerialVersionUID to 2L and keep the already set ones as is.

Let me know what you think! Thanks!

@regadas
Copy link
Contributor Author

regadas commented Sep 4, 2020

Hi @SethTisue and @lrytz not sure who to ping. Any thoughts? Thanks!

Copy link
Contributor

@NthPortal NthPortal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the UIDs should be 3L not 2L, as collections are not compatible across Scala versions.

Other than that, LGTM!

@lrytz
Copy link
Member

lrytz commented Sep 7, 2020

the UIDs should be 3L not 2L

Note that this PR targets 2.12.x


I think we remain serialization compatible between minor releases, the test t8549.scala (SerializationStabilityTest.scala in 2.13.x) checks that (at least to some degree).

Java's default serialization always includes the serial version UID. If not specified explicitly (using an annotation in Scala, a field in Java), the value is calculated based on the class structure. When the UID doesn't match on deserialization, an InvalidClassException is thrown.

Therefore I don't think we can just set the serial version UID to 2 (or 3) for classes that currently don't have an annotation, as it will break serialization compatibility.

What we can do however is make the calculated UID explicit and put it into an annotation. The serialver command line tool displays calculated UIDs:

$> serialver -classpath $(cs fetch -p org.scala-lang:scala-library:2.11.12) 'scala.collection.immutable.BitSet$BitSet2'
scala.collection.immutable.BitSet$BitSet2:    private static final long serialVersionUID = 5802956648923438352L;

@lrytz
Copy link
Member

lrytz commented Sep 7, 2020

Let me add that adding an explicit @SerialVersionUID is very much recommended, because the one that's calculated automatically is sensitive to changes that don't actually affect serialization compatibility, such as adding a public method. Ideally this should come with a test that checks the stability of the serialized form.

See scala/scala-dev#237.

@NthPortal
Copy link
Contributor

Note that this PR targets 2.12.x

gah, I always miss that. sorry!

@SethTisue
Copy link
Member

@regadas interested in continuing with this?

@regadas
Copy link
Contributor Author

regadas commented Oct 7, 2020

Hi @SethTisue yeah sorry for the delay! I was on vacation recently and I was still catching up! I'll have a look at the comments! Thx for the poke!

@dwijnand dwijnand modified the milestones: 2.12.13, 2.12.14 Oct 16, 2020
@SethTisue
Copy link
Member

@regadas closing for inactivity, but we can reopen anytime

@SethTisue SethTisue closed this Dec 4, 2020
@SethTisue SethTisue removed this from the 2.12.14 milestone Dec 4, 2020
@mallman
Copy link

mallman commented Dec 8, 2020

I'm confused. Is this going to be fixed in 2.12? I'm running into this problem with Spark 3.0.1 on Scala 2.12. Spark 3.0.1 seems to bundle 2.12.10, which is not compatible with 2.12.12 due to this issue. I believe the incompatibility was introduced by b8226e1.

@SethTisue
Copy link
Member

SethTisue commented Dec 8, 2020

@mallman since we haven't heard from @regadas in a while, you (or another contributor) are free to submit a new PR on the same theme

@mallman
Copy link

mallman commented Dec 8, 2020

I don't know how to fix this. Revert the commit?

@SethTisue
Copy link
Member

SethTisue commented Dec 8, 2020

I don't know how to fix this.

see @lrytz's #9166 (comment) — followup questions welcome

@mallman
Copy link

mallman commented Dec 8, 2020

Let's make sure we're on the same page. Is this serialization issue a bug?

@SethTisue
Copy link
Member

yes, it is scala/bug#5046, which was fixed for 2.13 but not for 2.12

@regadas
Copy link
Contributor Author

regadas commented Dec 8, 2020

Hi @SethTisue Sorry for this, tbh i completely forgot to follow up on this! Let me revive this this week as I have some time now /cc @mallman

@SethTisue SethTisue reopened this Dec 8, 2020
@scala-jenkins scala-jenkins added this to the 2.12.14 milestone Dec 8, 2020
@SethTisue SethTisue marked this pull request as draft December 8, 2020 20:03
@mallman
Copy link

mallman commented Dec 9, 2020

I'm going to stick with 2.12.10 for now. I don't have the time to work on a PR for this.

@mallman
Copy link

mallman commented Dec 9, 2020

Hi @SethTisue Sorry for this, tbh i completely forgot to follow up on this! Let me revive this this week as I have some time now /cc @mallman

Thank you @regadas.

@regadas regadas force-pushed the 2.12.x_serial_version branch 2 times, most recently from 8191a64 to 9d1b083 Compare December 10, 2020 21:27
Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge this after 2.12.13, we should update these two UIDs to their 2.12.13 value.

2.13.13 is now out, so once we've done the above we can merge this.

@mallman
Copy link

mallman commented Jan 13, 2021

If we merge this after 2.12.13, we should update these two UIDs to their 2.12.13 value.

Sorry, maybe I misunderstand. To be clear, will 2.12.14 be fully serialization-compatible with 2.12.10?

@lrytz
Copy link
Member

lrytz commented Jan 14, 2021

will 2.12.14 be fully serialization-compatible with 2.12.10?

I don't think so, there are classes without @SerialVersionUID that changed between 2.12.10 and 2.12.14, so instances serialized in 2.12.10 cannot be de-serialized in 2.12.14. De-serialization will fail because the (calculated) SerialVersionUID is different.

The best we can do is to add @SerialVersionUID annotations that correspond to the calculated value of the last release, which is what this PR does (currently, this PR sets the values of 2.12.12). However, there are two cases where the calculated value changes between 2.12.12 and 2.12.13, so we need to update this PR to use the 2.12.13 values.

@dwijnand
Copy link
Member

An example of how to get the SerialVersionUID: #8778 (comment).

@regadas
Copy link
Contributor Author

regadas commented Jan 14, 2021

Hello 👋 I can update this to reflect the recent 2.12.13 release. /cc @lrytz @dwijnand

@mallman
Copy link

mallman commented Jan 14, 2021

The best we can do is to add @serialversionuid annotations that correspond to the calculated value of the last release, which is what this PR does (currently, this PR sets the values of 2.12.12). However, there are two cases where the calculated value changes between 2.12.12 and 2.12.13, so we need to update this PR to use the 2.12.13 values.

Let me give some more background around my query. Spark 3.0.1 ships with Scala 2.12.10. When I try to run a Spark job with Scala 2.12.12 I encounter a serialization failure:

java.io.InvalidClassException: scala.collection.mutable.WrappedArray$ofRef; local class incompatible: stream classdesc serialVersionUID = 3456489343829468865, local class serialVersionUID = 1028182004549731694

From a practical perspective, I'm hoping to see Spark 3.0.1 (+) become compatible with maintenance releases of Scala 2.12 moving forward, so we are not stuck with Scala 2.12.10. I know that the OP referenced Flink compatibility issues as well. Is that a shared goal here, and is it achievable?

@SethTisue
Copy link
Member

(MiMa part needs rebase because of #9436)

@SethTisue SethTisue marked this pull request as draft January 26, 2021 17:05
@lrytz
Copy link
Member

lrytz commented Feb 15, 2021

@mallman sorry for my late reply!

We probably could set the explicit SerialVersionUIDs in this PR to the values that were valid in 2.12.10, but that would be quite an arbitrary choice (current Spark is using it, but other projects might be on a different version). So I believe that the best way forward is to use the values of our latest release (2.12.13). Once there's a spark release built with 2.12.13 out, a WrappedArray$ofRef serialized on a newer minor Scala releases (2.12.13+) will work.

Does that sound OK?

@regadas do you have time to rebase this to fix the merge conflicts, and to update the annotations to the 2.12.13 values?

@mallman
Copy link

mallman commented Feb 16, 2021

@mallman sorry for my late reply!

We probably could set the explicit SerialVersionUIDs in this PR to the values that were valid in 2.12.10, but that would be quite an arbitrary choice (current Spark is using it, but other projects might be on a different version). So I believe that the best way forward is to use the values of our latest release (2.12.13). Once there's a spark release built with 2.12.13 out, a WrappedArray$ofRef serialized on a newer minor Scala releases (2.12.13+) will work.

Does that sound OK?

@regadas do you have time to rebase this to fix the merge conflicts, and to update the annotations to the 2.12.13 values?

Hi @lrytz. Your perspective makes sense—let's not break things that were built against 2.12.12 or 2.12.13.

I'm not sure if the Spark team is aware of this issue. I didn't find anything from performing a cursory search of their issue tracker.

Their current master pom.xml still lists Scala 2.12.10, and Spark 3.1.1 is at rc2 at this point. I will try to raise an issue and submit a PR to upgrade to Spark to Scala 2.12.13, but I think it's unlikely it will be merged in time for Spark 3.1.1.

Thank you.

@smarter
Copy link
Member

smarter commented Feb 16, 2021

I will try to raise an issue and submit a PR to upgrade to Spark to Scala 2.12.13

That upgrade was previously tried and reverted due to a bug: apache/spark#31223 (comment) (the fix for that bug will be in 2.12.14).

@mallman
Copy link

mallman commented Feb 16, 2021

I will try to raise an issue and submit a PR to upgrade to Spark to Scala 2.12.13

That upgrade was previously tried and reverted due to a bug: apache/spark#31223 (comment) (the fix for that bug will be in 2.12.14).

Thank you for pointing that out.

@regadas
Copy link
Contributor Author

regadas commented Feb 17, 2021

@lrytz I'll spend some time on this today.

@regadas regadas force-pushed the 2.12.x_serial_version branch from 6e709bc to 0dc579e Compare February 17, 2021 22:48
@regadas regadas marked this pull request as ready for review February 17, 2021 23:07
@regadas
Copy link
Contributor Author

regadas commented Feb 17, 2021

@lrytz I think I addressed everything let me know If I missed smth.

@regadas regadas requested review from dwijnand and lrytz February 18, 2021 07:24
@lrytz lrytz force-pushed the 2.12.x_serial_version branch from 0dc579e to a5c4802 Compare February 18, 2021 07:40
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @regadas!

@lrytz lrytz merged commit fcc5845 into scala:2.12.x Feb 18, 2021
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
qinghui-xu added a commit to qinghui-xu/flink that referenced this pull request Sep 12, 2025
Java serialization issue fixed in scala 2.12.14: scala/scala#9166
Remove `reporter.printSummary` after the scala file compilation, because this api has been removed in scala 2.12.13
qinghui-xu added a commit to criteo-forks/flink that referenced this pull request Sep 15, 2025
Java serialization issue fixed in scala 2.12.14: scala/scala#9166
Remove `reporter.printSummary` after the scala file compilation, because this api has been removed in scala 2.12.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants