-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some null returns from JDK io/nio/regex API to
DefaultNullnessAnnotations
- Loading branch information
1 parent
423818a
commit 164ac68
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
findbugsTestCases/src/java/nullnessAnnotations/returnValue/TestNullReturnsInJdk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package nullnessAnnotations.returnValue; | ||
|
||
import java.io.File; | ||
import java.io.FileFilter; | ||
import java.io.FilenameFilter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.regex.Pattern; | ||
|
||
import edu.umd.cs.findbugs.annotations.ExpectWarning; | ||
|
||
public class TestNullReturnsInJdk { | ||
|
||
private static final Path PATH = Paths.get(""); | ||
private static final File FILE = PATH.toFile(); | ||
private static final Pattern PATTERN = Pattern.compile(""); | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe1(){ | ||
use(PATTERN.matcher("").group(2).length()); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe2(){ | ||
use(PATTERN.matcher("").group("bla").length()); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe3() throws IOException{ | ||
use(Files.probeContentType(PATH).length()); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe4() throws IOException{ | ||
use(PATH.getFileName().getNameCount()); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe5() throws IOException{ | ||
use(PATH.getParent().getNameCount()); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe6() throws IOException{ | ||
use(PATH.getRoot().getNameCount()); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe7() throws IOException{ | ||
use(FILE.list().length); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe8() throws IOException{ | ||
use(FILE.list(null).length); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe9() throws IOException{ | ||
use(FILE.listFiles().length); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe10() throws IOException{ | ||
use(FILE.listFiles((FileFilter)null).length); | ||
} | ||
|
||
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | ||
void npe11() throws IOException{ | ||
use(FILE.listFiles((FilenameFilter)null).length); | ||
} | ||
|
||
private void use(Object o) { | ||
System.out.println(o); | ||
} | ||
} |