bug icon indicating copy to clipboard operation
bug copied to clipboard

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

Open noresttherein opened this issue 1 year ago • 1 comments

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.

noresttherein avatar Jan 06 '24 19:01 noresttherein

happens in Scala 3.4.0-RC3 as well

SethTisue avatar Jan 26 '24 22:01 SethTisue