Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare CompletableFuture.completedStage(value) to accept null values #1395

Merged
merged 5 commits into from Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
Expand Up @@ -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", "<init>", "(Ljava/lang/String;)V",
false, 0, NullnessAnnotation.CHECK_FOR_NULL);
Expand Down
32 changes: 32 additions & 0 deletions 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 <a href="https://github.com/spotbugs/spotbugs/issues/1397">GitHub issue</a>
*/
public class Issue1397 {
CompletionStage<Void> completedFuture() {
// 1st argument of CompletableFuture#completedStage(U) should be nullable
return CompletableFuture.completedStage(null);
}
}