Skip to content

Array().take().toArray throws ClassCastException #139

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

Closed
scabug opened this issue Sep 27, 2007 · 4 comments
Closed

Array().take().toArray throws ClassCastException #139

scabug opened this issue Sep 27, 2007 · 4 comments

Comments

@scabug
Copy link

scabug commented Sep 27, 2007

The following code works in 2.6.0-final but throws and exception in
trunk r12940:

object Test extends Application
{
  val a = Array[String]("a", "b", "c")
  System.out.println(a)

  val b = a.take(1)
  System.out.println(b)

  val c : Array[String] = b.toArray
  System.out.println(c)

  val d : Array[String] = b
  System.out.println(d)
}

The output is:

[Ljava.lang.String;@1a125f0
Array(a)
java.lang.ExceptionInInitializerError
        at Test.main(t.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at scala.tools.nsc.ObjectRunner$$$$anonfun$$0.apply(ObjectRunner.scala:75)
        at scala.tools.nsc.ObjectRunner$$.withContextClassLoader(ObjectRunner.scala:49)
        at scala.tools.nsc.ObjectRunner$$.run(ObjectRunner.scala:74)
        at scala.tools.nsc.MainGenericRunner$$.main(MainGenericRunner.scala:154)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
        at Test$$.<init>(t.scala:12)
        at Test$$.<clinit>(t.scala)
        ... 10 more

Oddly enough, putting everything in one line works:

Welcome to Scala version 2.6.0.12940.20070926-175352.
Type in expressions to have them evaluated.
Type :help for more information.

scala> Array[String]("abc", "def").take(1).toArray
res0: Array[String] = [Ljava.lang.String;@d5e270
@scabug
Copy link
Author

scabug commented Sep 27, 2007

Imported From: https://issues.scala-lang.org/browse/SI-139?orig=1
Reporter: @blair
Assignee: @mcdirmid

@scabug
Copy link
Author

scabug commented Sep 28, 2007

@michelou said:
a.take(1) returns type Array.Projection[String] !!

@scabug
Copy link
Author

scabug commented Oct 2, 2007

@mcdirmid said:
used create like I was probably supposed to. Would be nice if BoxedAnyRefArray was documented better.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone 2.6.1 deleted

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

1 participant