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

Arbitrary functions are not serializable with Scala 2.12 #342

Closed
ttim opened this issue Jul 12, 2017 · 2 comments · Fixed by #343
Closed

Arbitrary functions are not serializable with Scala 2.12 #342

ttim opened this issue Jul 12, 2017 · 2 comments · Fixed by #343

Comments

@ttim
Copy link

ttim commented Jul 12, 2017

Due to the bug in Scala 2.12 https://issues.scala-lang.org/browse/SI-10232 generated arbitrary functions in scalacheck are not serializable. Fix for that is to split ArbitraryArities and GenArities into different traits.

Here is a repro (should be done with scala 2.12):

import org.scalacheck.Arbitrary._
val f = arbitrary[Int => Int]
val outputStream = new java.io.ByteArrayOutputStream()
val objectOutputStream = new java.io.ObjectOutputStream(outputStream)
objectOutputStream.writeObject(f)
objectOutputStream.close
val inputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray)
val objectInputStream = new java.io.ObjectInputStream(inputStream)
objectInputStream.readObject()

Should work but instead cause next exception:

java.io.IOException: unexpected exception type
  at java.io.ObjectStreamClass.throwMiscException(ObjectStreamClass.java:1582)
  at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1154)
  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1817)
  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2018)
  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1942)
  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1808)
  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
  ... 29 elided
Caused by: java.lang.reflect.InvocationTargetException: java.lang.BootstrapMethodError: too many bootstrap method arguments
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at java.lang.invoke.SerializedLambda.readResolve(SerializedLambda.java:230)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1148)
  ... 36 more
Caused by: java.lang.BootstrapMethodError: too many bootstrap method arguments
  at java.lang.invoke.CallSite.makeSite(CallSite.java:320)
  at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307)
  at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297)
  at org.scalacheck.GenArities.$deserializeLambda$(GenArities.scala)
  ... 46 more
@travisbrown
Copy link

I've just confirmed that this issue can be resolved by instantiating FunctionNs explicitly instead of using function literals, which means we don't have to break binary compatibility by splitting up the traits. I'll send a PR in the next half hour or so.

@ttim
Copy link
Author

ttim commented Jul 13, 2017

@travisbrown this is awesome, thank you!

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 a pull request may close this issue.

2 participants