-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
Milestone
Description
There are already several tickets related to Java interop with protected methods. This may have the same root cause as one of them but it seems worth reporting separately because it's a regression (which I didn't see in the other tickets) and doesn't require any casts.
Given Java source file
package foo;
public class Foo {
protected void foo() {}
}and a Scala source file:
package bar
import foo.Foo
trait BarMixin { self: Foo =>
protected def foo: Unit
def bar = foo
}
class Bar extends Foo with BarMixin
object Bar extends App {
(new Bar).foo // 1
(new Bar).bar // 2
}Both call sites compile in 2.12 and 2.13. Call site 1 always fails with
[error] Exception in thread "main" java.lang.IllegalAccessError: class bar.Bar$ tried to access protected method 'void foo.Foo.foo()' (bar.Bar$ and foo.Foo are in unnamed module of loader 'app')
[error] at bar.Bar$.delayedEndpoint$bar$Bar$1(Bar.scala:13)
[error] at bar.Bar$delayedInit$body.apply(Bar.scala:12)
[error] at scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] at scala.Function0.apply$mcV$sp$(Function0.scala:39)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
[error] at scala.App.$anonfun$main$1(App.scala:76)
[error] at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error] at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
[error] at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
[error] at scala.collection.AbstractIterable.foreach(Iterable.scala:919)
[error] at scala.App.main(App.scala:76)
[error] at scala.App.main$(App.scala:74)
[error] at bar.Bar$.main(Bar.scala:12)
[error] at bar.Bar.main(Bar.scala)
Call site 2 works as expected up to 2.13.6 but fails in 2.13.7 and higher:
[error] Exception in thread "main" java.lang.IllegalAccessError: class bar.BarMixin tried to access protected method 'void foo.Foo.foo()' (bar.BarMixin and foo.Foo are in unnamed module of loader 'app')
[error] at bar.BarMixin.bar(Bar.scala:7)
[error] at bar.BarMixin.bar$(Bar.scala:7)
[error] at bar.Bar.bar(Bar.scala:10)
[error] at bar.Bar$.delayedEndpoint$bar$Bar$1(Bar.scala:14)
[error] at bar.Bar$delayedInit$body.apply(Bar.scala:12)
[error] at scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] at scala.Function0.apply$mcV$sp$(Function0.scala:39)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
[error] at scala.App.$anonfun$main$1(App.scala:76)
[error] at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error] at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
[error] at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
[error] at scala.collection.AbstractIterable.foreach(Iterable.scala:926)
[error] at scala.App.main(App.scala:76)
[error] at scala.App.main$(App.scala:74)
[error] at bar.Bar$.main(Bar.scala:12)
[error] at bar.Bar.main(Bar.scala)
lrytz