Accessing internal class from Java tests in the same module

I have a module organized as such:

          ...(some java files)

Where Foo.kt is:


internal class Foo {
  fun bar() = "bar"

and is:


import org.testng.annotations.Test;

public class FooTest {
  public void testBar() {
    Foo foo = new Foo();

I’m getting errors at references to Foo on

Usage of Kotlin internal declaration from different module

However, I believe it’s still in the same foo module, so why is this error happening?

The reason of why I’m doing this is I am currently trying to port some of my code from Java (inside main/java) to Kotlin (inside main/kotlin). Previously the Java classes has package-private modifiers.

Note that if I convert the into Kotlin (via IDEA convert functionality) the errors don’t happen, so it only happens when the test file is in Java.

Would really appreciate the help!

1 Like

Huh, after trying it again, the error seems to be only an IDEA inspection error, and the test runs fine. Is this expected and is there any way to fix this?

Found it: Editor > Inspections > Kotlin > Java Interop Issues > Usage of Kotlin internal declaration from Java, and setting it to warning instead of error makes it happy. As I may still be naive, does anyone know what issues may arise from this?

This is still the case in IntelliJ Ultimate 2018.3.2