https://kotlinlang.org logo
p

Pacane

12/09/2019, 8:49 PM
is there something to tell the Java to Kotlin converter in Intellij that some fields are non-nullable, so that the converter doesn't make everything nullable by default? I tried adding some
@NotNull
annotations on fields/construction parameters, but the converter still makes everything nullable
i

Ilya Kirillov [JB]

12/09/2019, 10:10 PM
This looks like https://youtrack.jetbrains.com/issue/KT-34987 which is fixed in 1.3.61. Which version of Kotlin plugin do you use?
p

Pacane

12/09/2019, 10:12 PM
1.3.61
IntelliJ IDEA 2019.3 (Ultimate Edition) Build #IU-193.5233.102, built on November 27, 2019
i

Ilya Kirillov [JB]

12/09/2019, 10:25 PM
Just checked on 1.3.61:
Copy code
import org.jetbrains.annotations.NotNull;

public class Test {
    void Test(@NotNull String notNullParam) {}
}
generates:
Copy code
class Test internal constructor(notNullParam: String)
Could you please provide me with reproducible example?
p

Pacane

12/09/2019, 10:26 PM
sure 1s
It seems to be happening with an abstract class extending another class
trying to get a minimal reproducible case
This is
B.java
Copy code
package com.bitboxusa.core.abstractions.eventbus;

import org.jetbrains.annotations.NotNull;

public class B {
  @NotNull protected final Integer b;

  B(@NotNull Integer b) {
    this.b = b;
  }
}
This is
A.java
Copy code
package com.bitboxusa.core.abstractions.eventbus;

import org.jetbrains.annotations.NotNull;

public abstract class A extends B {
  public A(@NotNull Integer some) {
    super(some);
  }
}
I'm only converting A.java to Kotlin so far
ending up with
Copy code
package com.bitboxusa.core.abstractions.eventbus

import org.jetbrains.annotations.NotNull

abstract class A(some: @NotNull Int?) : B(some!!)
I'm going through this progressive migration
i

Ilya Kirillov [JB]

12/09/2019, 10:46 PM
Still getting valid result for you example:
Copy code
abstract class A(some: Int) : B(some)
As a temporary solution, you can try use old version of J2K, which can be enabled by disabling
Settings -> Languages & Fraameworks -> Kotilin -> Use New Java to Kotlin Conversion
p

Pacane

12/09/2019, 10:47 PM
I'll try that, ty