scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

`IllegalAccessError` from `super[Object].clone` in a trait #12926

Open noresttherein opened 5 months ago

noresttherein commented 5 months ago

Reproduction steps

Scala version: 2.13.11

    trait Clone extends AnyRef with Cloneable {
        override def clone :Clone = super[Object].clone.asInstanceOf[Clone]
    }
    class C extends Clone
    (new C).clone

Problem

Exception in thread "main" java.lang.IllegalAccessError: class Playground$Clone tried to access protected method 'java.lang.Object java.lang.Object.clone()' (Playground$Clone is in unnamed module of loader 'app'; java.lang.Object is in module java.base of loader 'bootstrap')
    at Playground$Clone.clone(Playground.scala:114)
    at Playground$Clone.clone$(Playground.scala:114)
    at Playground$C.clone(Playground.scala:116)
    at Playground$.delayedEndpoint$Playground$1(Playground.scala:117)
    at Playground$delayedInit$body.apply(Playground.scala:106)
    at scala.Function0.apply$mcV$sp(Function0.scala:42)
    at scala.Function0.apply$mcV$sp$(Function0.scala:42)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
    at scala.App.$anonfun$main$1(App.scala:98)
    at scala.App.$anonfun$main$1$adapted(App.scala:98)
    at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:576)
    at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:574)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:933)
    at scala.App.main(App.scala:98)
    at scala.App.main$(App.scala:96)
    at Playground$.main(Playground.scala:106)
    at Playground.main(Playground.scala)

I understand that 'super to class from an interface' is problematic in itself, but IllegalAccessError at runtime is still bad.

SethTisue commented 5 months ago

happens in Scala 3.4.0-RC3 as well