Files
Andrey.Cherkasov 0d10ba565e [java] Fix test data files after inspection description updating
GitOrigin-RevId: faa9f564b7a37e4c1165c24f904994b951adfccd
2021-03-18 10:49:54 +00:00

29 lines
786 B
Java

// "Fix all ''Optional' can be replaced with sequence of 'if' statements' problems in file" "true"
import java.util.*;
class Test {
String orElseThrowDefault(String in) {
if (in == null || in.length() <= 12) throw new NoSuchElementException("No value present");
return in;
}
String orElseLambda(String in) {
if (in == null || in.length() <= 12) throw new IllegalArgumentException("value is null");
return in;
}
String orElseThrowWithSideEffect(String in) {
if (in == null) throw sideEffect();
String s = in.substring(3);
if (s.length() <= 12) throw sideEffect();
return s;
}
private RuntimeException sideEffect() {
System.out.println("side effect!");
return new IllegalArgumentException("value is null")
}
}