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

Array created using ClassTag[Array[Nothing]] cannot hold Array[Nothing] created by new #9754

Open
scabug opened this issue Apr 14, 2016 · 3 comments
Milestone

Comments

@scabug
Copy link

scabug commented Apr 14, 2016

The following program

import scala.reflect.ClassTag

object Program {
  def test[T: ClassTag](x: T) = {
    val arr = new Array[T](1)
    println(arr.getClass)
    println(x.getClass)
    arr(0) = x
  }

  def main(args: Array[String]): Unit = {
    test(new Array[Nothing](0))
  }

}

throws the exception java.lang.ArrayStoreException:

[error] (run-main-8) java.lang.ArrayStoreException: [Ljava.lang.Object;
java.lang.ArrayStoreException: [Ljava.lang.Object;
	at scala.runtime.ScalaRunTime$.array_update(ScalaRunTime.scala:89)
	at Program$.test(Program.scala:8)
	at Program$.main(Program.scala:12)
	at Program.main(Program.scala)
	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:497)

The output of the program

class [[Lscala.runtime.Nothing$;
class [Ljava.lang.Object;

explains the problem. The array arr created using ClassTag has element type Array[scala.runtime.Nothing$] but array created by new has type Array[java.lang.Object].

Same exception is thrown with Null. For other types it works fine.

@scabug
Copy link
Author

scabug commented Apr 14, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9754?orig=1
Reporter: Radek Micek (radekm)
See #5353, #7543

@scabug
Copy link
Author

scabug commented Sep 29, 2016

@SethTisue said:
is this already covered by SI-5353 and/or SI-7543?

@scabug scabug added the quickfix label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue
Copy link
Member

Scala 3 ticket in the Array[Nothing] space: scala/scala3#9586

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

2 participants