Use @Present annotation on the method that is assuredly returning a non-empty optional
Open
@shubhamugare is already working on this.
Since Nov 1, 2019.
- Dominant language
- Java
- Stars
- 4.1k
- Forks
- 370
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 68
Description
Use @Present annotation on the return of the method that is assuredly returning a non-empty optional.
Following test should pass.
@Test
public void OptionalEmptinessPresentTest() {
compilationHelper
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.lib.unannotated",
"-XepOpt:NullAway:CheckOptionalEmptiness=true"))
.addSourceLines(
"TestNegative.java",
"package com.uber;",
"import com.google.common.base.Optional;",
"rg.checkerframework.checker.optional.qual.Present",
"import com.google.common.base.Function;",
"public class TestNegative {",
" class ABC { ",
" @present Optional<Object> getTheOptional(int x){",
" if(x != 0){",
" return Optional.of(new Object());",
" }",
" return Optional.of(new Object());",
" }",
" }",
" void foo() {",
" ABC abc = new ABC();",
" // no error since @present annotation on the invoked method",
" abc.getTheOptional(5).get().toString();",
" }",
" }",
"}")
.doTest();
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.