diff --git a/build.gradle b/build.gradle index 2d7841d..0547b9c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ - plugins { id 'java-library' + id "net.ltgt.errorprone" version "3.1.0" } repositories { @@ -14,19 +14,30 @@ } } -compileJava { +tasks.withType(JavaCompile) { options.compilerArgs << '-Xlint:unchecked' options.compilerArgs << '-Xlint:rawtypes' options.release = 21 -} - -compileTestJava { - options.compilerArgs << '-Xlint:unchecked' - options.compilerArgs << '-Xlint:rawtypes' - options.release = 21 + if (!name.toLowerCase().contains("test")) { + options.errorprone { + check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) + option("NullAway:AnnotatedPackages", "com.github.tonivade.vavr.effect") + option("NullAway:SuggestSuppressions", "true") + } + } else { + options.errorprone { + option("NullAway:AnnotatedPackages", "com.github.tonivade.vavr.effect") + option("ExcludedPaths", ".*/src/test/java/.*") + } + } } dependencies { + errorprone 'com.google.errorprone:error_prone_core:2.25.0' + errorprone 'com.uber.nullaway:nullaway:0.10.24' + + compileOnly 'com.google.code.findbugs:jsr305:3.0.2' + api 'io.vavr:vavr:0.10.4' testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2' diff --git a/src/main/java/com/github/tonivade/vavr/effect/IO.java b/src/main/java/com/github/tonivade/vavr/effect/IO.java index 90073c4..2f0df53 100644 --- a/src/main/java/com/github/tonivade/vavr/effect/IO.java +++ b/src/main/java/com/github/tonivade/vavr/effect/IO.java @@ -24,6 +24,8 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import javax.annotation.Nullable; + import io.vavr.CheckedConsumer; import io.vavr.CheckedFunction0; import io.vavr.CheckedRunnable; @@ -792,7 +794,7 @@ static final class Cancellable implements IOConnection { - private IO cancelToken; + private IO cancelToken = IO.UNIT; private final AtomicReference state = new AtomicReference<>(StateIO.INITIAL); private Cancellable() { } @@ -856,13 +858,19 @@ final class CallStack { + @Nullable private StackItem top = new StackItem<>(); void push() { - top.push(); + if (top != null) { + top.push(); + } } void pop() { + if (top == null) { + return; + } if (top.count() > 0) { top.pop(); } else { @@ -871,6 +879,9 @@ } void add(PartialFunction> mapError) { + if (top == null) { + return; + } if (top.count() > 0) { top.pop(); top = new StackItem<>(top); @@ -904,16 +915,18 @@ private int count = 0; private final Deque>> recover = new ArrayDeque<>(); + @Nullable private final StackItem prev; StackItem() { this(null); } - StackItem(StackItem prev) { + StackItem(@Nullable StackItem prev) { this.prev = prev; } + @Nullable StackItem prev() { return prev; }