Files
kotlin-fork/j2k/testData/fileOrElement/nullability/LocalValReassignment.java
T
Simon Ogorodnik a6e153312c Prevent early deleting of not-null assertions
Before val to var conversion applied, smart-cast can cause
dropping not-null assertion, which will be required when val will
become var
2017-06-07 21:21:37 +03:00

35 lines
840 B
Java
Vendored

import org.jetbrains.annotations.*;
class A {
/* rare nullable, handle with caution */
public String nullableString() {
if (Math.random() > 0.999) {
return "a string";
}
return null;
}
public void takesNotNullString(@NotNull String s) {
System.out.println(s.substring(1));
}
public void aVoid() {
String aString;
if (nullableString() != null) {
aString = nullableString();
if (aString != null) {
for (int i = 0; i < 10; i++) {
takesNotNullString(aString); // Bang-bang here
aString = nullableString();
}
}
else {
aString = "aaa";
}
}
else {
aString = "bbbb";
}
}
}