Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static CreateTranscriptionsReq of(String fileName, byte[] fileBytes) {
}

public static CreateTranscriptionsReq of(File file) {
return CreateTranscriptionsReq.builder().file(file).build();
return CreateTranscriptionsReq.builder().file(file).fileName(file.getName()).build();
}
Comment on lines 35 to 37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add null-check and guard against empty getName() to avoid NPE/invalid names

If file is null, this method throws NPE. Also, File#getName() can be empty for edge cases (e.g., platform root paths). Add validation and a fallback.

Apply this diff within this method:

   public static CreateTranscriptionsReq of(File file) {
-    return CreateTranscriptionsReq.builder().file(file).fileName(file.getName()).build();
+    if (file == null) {
+      throw new IllegalArgumentException("file must not be null");
+    }
+    String name = file.getName();
+    if (name == null || name.isEmpty()) {
+      // Fallback for unconventional paths (e.g., root). Use path as a last resort.
+      name = file.getPath();
+    }
+    return CreateTranscriptionsReq.builder()
+        .file(file)
+        .fileName(name)
+        .build();
   }

Optional: annotate the parameter with Lombok @NonNull to enforce checks at compile-time as well.

🤖 Prompt for AI Agents
In
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java
around lines 35-37, the factory method blindly uses file and file.getName(),
which can cause NPE if file is null and can yield an empty filename for edge
cases; add a null-check that throws a clear IllegalArgumentException (or return
an Optional/handle per project convention) when file is null, compute name =
file.getName(); if name is null or empty use a sensible fallback like "unknown"
or derive from file.getPath(), then build with that name; optionally annotate
the parameter with Lombok @NonNull to enforce compile-time checks.


public static CreateTranscriptionsReq of(String filePath) {
Expand Down
Loading