Skip to content

Commit 8113ed2

Browse files
committed
fix: harden null-safe path and extension handling
1 parent 1038ad7 commit 8113ed2

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/main/java/me/tamkungz/codecmedia/internal/StubCodecMediaEngine.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,9 @@ public PlaybackResult play(Path input, PlaybackOptions options) throws CodecMedi
804804

805805
@Override
806806
public ValidationResult validate(Path input, ValidationOptions options) {
807+
if (input == null) {
808+
return new ValidationResult(false, List.of(), List.of("Input file is required"));
809+
}
807810
ValidationOptions effective = options != null ? options : ValidationOptions.defaults();
808811
boolean exists = Files.exists(input);
809812
if (!exists) {
@@ -925,13 +928,23 @@ public ValidationResult validate(Path input, ValidationOptions options) {
925928
}
926929

927930
private static void ensureExists(Path input) throws CodecMediaException {
931+
if (input == null) {
932+
throw new CodecMediaException("Input file is required");
933+
}
928934
if (!Files.exists(input)) {
929935
throw new CodecMediaException("File does not exist: " + input);
930936
}
931937
}
932938

933939
private static String extractExtension(Path input) {
934-
String name = input.getFileName().toString();
940+
if (input == null) {
941+
return "";
942+
}
943+
Path fileName = input.getFileName();
944+
if (fileName == null) {
945+
return "";
946+
}
947+
String name = fileName.toString();
935948
int dotIndex = name.lastIndexOf('.');
936949
if (dotIndex < 0 || dotIndex == name.length() - 1) {
937950
return "";
@@ -1022,6 +1035,9 @@ private static Map<String, String> readEmbeddedMetadata(Path input, String norma
10221035
}
10231036

10241037
private static String normalizeExtension(String format) {
1038+
if (format == null) {
1039+
return "";
1040+
}
10251041
String value = format.trim().toLowerCase(Locale.ROOT);
10261042
return value.startsWith(".") ? value.substring(1) : value;
10271043
}

0 commit comments

Comments
 (0)