diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d9370358f7..dfb68bc2647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. ### Fixed * Invalid HTML in the description of `LI_LAZY_INIT_UPDATE_STATIC` bug pattern ([#1383](https://github.com/spotbugs/spotbugs/pull/1383)) +* NP_NONNULL_PARAM_VIOLATION false-positive in CompletableFuture.completedStage(value) ([#1397](https://github.com/spotbugs/spotbugs/issues/1397)) ## 4.2.0 - 2020-11-28 ### Fixed diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/DefaultNullnessAnnotations.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/DefaultNullnessAnnotations.java index a1da51ef986..c9e563f2f55 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/DefaultNullnessAnnotations.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/DefaultNullnessAnnotations.java @@ -232,6 +232,8 @@ public static void addDefaultNullnessAnnotations(INullnessAnnotationDatabase dat "(Ljava/lang/Object;)Z", false, 0, NullnessAnnotation.NULLABLE); database.addMethodParameterAnnotation("java.util.concurrent.CompletableFuture", "completedFuture", "(Ljava/lang/Object;)Ljava/util/concurrent/CompletableFuture;", true, 0, NullnessAnnotation.NULLABLE); + database.addMethodParameterAnnotation("java.util.concurrent.CompletableFuture", "completedStage", + "(Ljava/lang/Object;)Ljava/util/concurrent/CompletionStage;", true, 0, NullnessAnnotation.NULLABLE); database.addMethodParameterAnnotation("java.util.concurrent.ExecutionException", "", "(Ljava/lang/String;)V", false, 0, NullnessAnnotation.CHECK_FOR_NULL); diff --git a/spotbugsTestCases/src/java11/Issue1397.java b/spotbugsTestCases/src/java11/Issue1397.java new file mode 100644 index 00000000000..1a9d15906f5 --- /dev/null +++ b/spotbugsTestCases/src/java11/Issue1397.java @@ -0,0 +1,32 @@ +/* + * Contributions to SpotBugs + * Copyright (C) 2021 Mikael Ståldal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package ghIssues; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + +/** + * @see GitHub issue + */ +public class Issue1397 { + CompletionStage completedFuture() { + // 1st argument of CompletableFuture#completedStage(U) should be nullable + return CompletableFuture.completedStage(null); + } +}