Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala 2.12.4: Cannot access protected static Java method from another package anymore

Tags:

I have java class with protected static method:

package parent;

public class Parent {

    protected static void parentMethod() {
        System.out.println("I'm in parent static method");
    }

}

Before Scala 2.12.4 (2.12.3) I could call this method from another package like this:

package child

import parent.Parent

class Child extends Parent {

  def childMethod = {
    println("I'm in child method and calling parentMethod")
    Parent.parentMethod()
  }

}

But Scala 2.12.4 does not compile this code. I'm getting the error:

Error:(9, 12) method parentMethod in object Parent cannot be accessed in object parent.Parent Access to protected method parentMethod not permitted because prefix type parent.Parent.type does not conform to object Child in package child where the access takes place Parent.parentMethod()

This access pattern was very important for me because JOOQ code generation uses this.

What happened?

like image 434
Teimuraz Avatar asked Jan 20 '18 06:01

Teimuraz


1 Answers

Nice catch, this is most likely a regression introduced by this PR, as part of a solution to this issue.

I've already opened a ticket for this that you can track. In the meanwhile, if this kind of access pattern is vital for your application, unfortunately I don't think you have much choice but to stick to Scala 2.12.3 for the time being.

Edit

The issue was already known and a fix has been already merged. As of the time of writing the patch is bound to be part of the 2.12.5 release.

like image 59
stefanobaghino Avatar answered Oct 10 '22 13:10

stefanobaghino