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

fs2 upgrade 2.2.0 - ClassCastException #1745

Closed
regis-leray opened this issue Jan 18, 2020 · 4 comments
Closed

fs2 upgrade 2.2.0 - ClassCastException #1745

regis-leray opened this issue Jan 18, 2020 · 4 comments

Comments

@regis-leray
Copy link
Contributor

regis-leray commented Jan 18, 2020

After upgrading fs2:2.0.1 to fs2:2.2.0 im getting this stacktrace, it looks there is some optimisation have been done with Chunk

I tried with fs2:2.1.0 and everything work fines

[info] - should readFile *** FAILED ***
[info]   java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [B ([Ljava.lang.Object; and [B are in module java.base of loader 'bootstrap')
[info]   at fs2.Chunk.toBytes(Chunk.scala:276)
[info]   at fs2.io.file.FileHandle$$anon$1.$anonfun$write$1(FileHandle.scala:148)
[info]   at scala.runtime.java8.JFunction0$mcI$sp.apply(JFunction0$mcI$sp.scala:17)
[info]   at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:87)
[info]   at cats.effect.internals.IORunLoop$.startCancelable(IORunLoop.scala:41)
[info]   at cats.effect.internals.IOBracket$BracketStart.run(IOBracket.scala:86)
[info]   at cats.effect.internals.Trampoline.cats$effect$internals$Trampoline$$immediateLoop(Trampoline.scala:70)
[info]   at cats.effect.internals.Trampoline.startLoop(Trampoline.scala:36)
[info]   at cats.effect.internals.TrampolineEC$JVMTrampoline.super$startLoop(TrampolineEC.scala:93)
[info]   at cats.effect.internals.TrampolineEC$JVMTrampoline.$anonfun$startLoop$1(TrampolineEC.scala:93)

if you want to see the whole code it is here =>
regis-leray/fs2-ftp#11

@mpilquist
Copy link
Member

mpilquist commented Jan 18, 2020

Thanks for the report. This reproduces:

> Chunk(0, 0).map(_.toByte).toArray
java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [B ([Ljava.lang.Object; and [B are in module java.base of loader 'bootstrap')

@mpilquist
Copy link
Member

Introduced by #1715. We could roll that back and release a 2.2.1. @CremboC any thoughts? Problem is that map is creating an Array[Any] but then later when toArray is called, it's cast to an Array[Byte].

@CremboC
Copy link
Contributor

CremboC commented Jan 19, 2020

I was worried that this could happen. Hoped that tests would catch this, but obviously was too optimistic! Could just deoptimise map back to what it was before, or just undo the whole PR. Up to you! Sorry about that.

Also could look into how ArraySeq map is implemented - afaik it's a Seq backed by an Array so should be very similar to what we're doing with Chunk

mpilquist added a commit that referenced this issue Jan 19, 2020
Fixed ClassCastException in Chunk#toArray, fixes #1745
@mpilquist
Copy link
Member

Fixed by #1746

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

No branches or pull requests

3 participants