Java: Don't extract method where it's not safe because of nullable result (IDEA-167391)

This commit is contained in:
Pavel Dolgov
2017-06-08 18:17:10 +03:00
parent 9ca8685340
commit a95807108c
5 changed files with 128 additions and 20 deletions
@@ -0,0 +1,21 @@
import org.jetbrains.annotations.Nullable;
class C {
private int[] list;
private int find(int id) {
Integer n = newMethod(id);
if (n != null) return n;
throw new RuntimeException();
}
@Nullable
private Integer newMethod(int id) {
for (int n : list) {
if (n == id) {
return n <= 0 ? 0 : n;
}
}
return null;
}
}