Files
kotlin-fork/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/safeCalls.kt
T
Dmitry Savvinov 4d951de616 Propagate nullability changes to enhancement for JSR-305 types
Fix TypeUtils.makeNullableAsSpecified for SimpleTypeWithEnhancement and
FlexibleTypeWithEnhancement: change nullability of enhancement too. This
fixes several false-positive warnings, like in KT-20855 and KT-20466.

Note that it removes warning in some cases (see testdata change for
uselessElvisRightIsNull.kt). However, this removes warning about
*unnecessary* elvis, i.e. this fixed introduces weak false-negatives, which
is acceptable for the moment.

#KT-20855 Fixed Target versions 1.2.30
#KT-20466 Fixed Target versions 1.2.30
#KT-21238 Fixed Target versions 1.2.30
2018-01-26 12:49:14 +03:00

73 lines
1.6 KiB
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_VARIABLE
// JSR305_GLOBAL_REPORT warn
// FILE: MyNotNull.java
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierNickname;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.PARAMETER})
@Nonnull
@TypeQualifierNickname
@Retention(RetentionPolicy.RUNTIME)
public @interface MyNotNull {}
// FILE: AnnotatedWithJsr.java
public class AnnotatedWithJsr {
@MyNotNull
public String getString() {
return null;
}
public void consumeString(@MyNotNull String s) { }
}
// FILE: AnnotatedWithJB.java
import org.jetbrains.annotations.NotNull;
public class AnnotatedWithJB {
public @NotNull String getString() {
return "hello";
}
public void consumeString(@NotNull String s) { }
}
// FILE: PlainJava.java
public class PlainJava {
public String getString() {
return null;
}
public void consumeString(String s) { }
}
// FILE: main.kt
val jsr: AnnotatedWithJsr = AnnotatedWithJsr()
val jsrNullable: AnnotatedWithJsr? = null
val jb: AnnotatedWithJB = AnnotatedWithJB()
val jbNullable: AnnotatedWithJB? = null
val platform: PlainJava = PlainJava()
val platformNullable: PlainJava? = null
fun safeCalls() {
val a = jsr.string<!UNNECESSARY_SAFE_CALL!>?.<!>length
val b = jsrNullable?.string?.length
val c = jb.string<!UNNECESSARY_SAFE_CALL!>?.<!>length
val d = jbNullable?.string?.length
val e = platform.string?.length
val f = platformNullable?.string?.length
}