From e6b208b3d829ab7bae3652efedb6b2e586f41310 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Thu, 12 Nov 2026 10:39:40 -0800 Subject: [PATCH 1/2] Consistent, documented null handling in FileType.isType() --- api/src/org/labkey/api/util/FileType.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/api/src/org/labkey/api/util/FileType.java b/api/src/org/labkey/api/util/FileType.java index fd2ac6d70db..ade9dd0acdf 100644 --- a/api/src/org/labkey/api/util/FileType.java +++ b/api/src/org/labkey/api/util/FileType.java @@ -490,22 +490,22 @@ public Path newFile(Path parent, String basename) return FileUtil.appendName(parent, getName(parent, basename)); } - public boolean isType(File file) + public boolean isType(@Nullable File file) { return isType(file, null, null); } - public boolean isType(FileLike file) + public boolean isType(@Nullable FileLike file) { - return isType(file.toNioPathForRead(), null, null); + return file != null && isType(file.toNioPathForRead(), null, null); } - public boolean isType(java.nio.file.Path path) + public boolean isType(@Nullable java.nio.file.Path path) { return isType(path, null, null); } - public boolean isType(java.nio.file.Path path, String contentType, byte[] header) + public boolean isType(@Nullable java.nio.file.Path path, String contentType, byte[] header) { if ((path == null) || (_dir != null && _dir.booleanValue() != Files.isDirectory(path))) return false; @@ -513,8 +513,7 @@ public boolean isType(java.nio.file.Path path, String contentType, byte[] header return isType(path.getFileName().toString(), contentType, header); } - - public boolean isType(File file, String contentType, byte[] header) + public boolean isType(@Nullable File file, String contentType, byte[] header) { if ((file == null) || (_dir != null && _dir.booleanValue() != file.isDirectory())) return false; @@ -525,7 +524,7 @@ public boolean isType(File file, String contentType, byte[] header) /** * Checks if the path matches any of the suffixes */ - public boolean isType(String filePath) + public boolean isType(@Nullable String filePath) { return isType(filePath, null, null); } From 5d6bf655078296fc32d07ca3b267250f290c77c0 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Thu, 12 Nov 2026 11:02:08 -0800 Subject: [PATCH 2/2] Annotate remaining isType() parameters and handle root paths --- api/src/org/labkey/api/util/FileType.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/src/org/labkey/api/util/FileType.java b/api/src/org/labkey/api/util/FileType.java index ade9dd0acdf..fbf5371be83 100644 --- a/api/src/org/labkey/api/util/FileType.java +++ b/api/src/org/labkey/api/util/FileType.java @@ -505,15 +505,17 @@ public boolean isType(@Nullable java.nio.file.Path path) return isType(path, null, null); } - public boolean isType(@Nullable java.nio.file.Path path, String contentType, byte[] header) + public boolean isType(@Nullable java.nio.file.Path path, @Nullable String contentType, byte @Nullable[] header) { if ((path == null) || (_dir != null && _dir.booleanValue() != Files.isDirectory(path))) return false; - return isType(path.getFileName().toString(), contentType, header); + // A root has no file name; use "" to match File.getName() + Path fileName = path.getFileName(); + return isType(fileName == null ? "" : fileName.toString(), contentType, header); } - public boolean isType(@Nullable File file, String contentType, byte[] header) + public boolean isType(@Nullable File file, @Nullable String contentType, byte @Nullable[] header) { if ((file == null) || (_dir != null && _dir.booleanValue() != file.isDirectory())) return false;