Skip to content

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

@noresttherein

Description

@noresttherein

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions