Scala 2.12.4: Unable to access Java protected static method from another package

I have a java class with a protected static method:

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

Prior to Scala 2.12.4 (2.12.3), I could call this method from another package as follows:

 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 get an error message:

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

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

What happened?

+5
source share
1 answer

A good catch is most likely the regression introduced by this PR as part of the solution to this issue .

I have already opened a ticket for this, which you can track. Meanwhile, if this type of access is vital to your application, unfortunately, I don’t think you have much choice but to stick with Scala 2.12.3.

Edit

The problem was already known, and the fix was already combined . At the time of writing, the patch should be part of release 2.12.5.

+4
source

Source: https://habr.com/ru/post/1274830/


All Articles