Skip to content

Commit

Permalink
Handle NPE in SysUtil#filesUnder
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Nov 15, 2024
1 parent 70f5b73 commit cadd7ba
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ public static List<File> filesUnder(File parent, Predicate<File> predicate) {
ArrayList<File> result = new ArrayList<>();

if(parent.isDirectory()) {
for(File child : parent.listFiles()) {
File[] files = parent.listFiles();
if(files == null) return result;

for(File child : files) {
result.addAll(filesUnder(child, predicate));
}
} else if(parent.exists() && (predicate != null && predicate.test(parent))) {
Expand All @@ -226,7 +229,10 @@ public static List<File> filesIn(File parent, Predicate<File> predicate) {
if(!parent.exists()) return result;

if(parent.isDirectory()) {
for(File f : parent.listFiles()) {
File[] files = parent.listFiles();
if(files == null) return result;

for(File f : files) {
if(predicate != null && predicate.test(f))
result.add(f);
}
Expand Down

0 comments on commit cadd7ba

Please sign in to comment.