-
Notifications
You must be signed in to change notification settings - Fork 90
fix: 修复文件名为空导致的异常 #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 修复文件名为空导致的异常 #119
Conversation
NullSnow
commented
Aug 26, 2025
- 在 CreateTranscriptionsReq 类中的 of(File file) 方法中增加了设置文件名的逻辑
- 解决TranscriptionService中获取文件名为空,导致的接口返回 {"detail":{"logid":"xxxx"},"code":4000,"msg":"The parameter file is invalid. It should follow the format: file. Please review your input."}
- 在 CreateTranscriptionsReq 类中的 of(File file) 方法中增加了设置文件名的逻辑
- 解决TranscriptionService中获取文件名为空,导致的接口返回 {"detail":{"logid":"2025082610304671C0F5314D04A5EED067"},"code":4000,"msg":"The parameter file is invalid. It should follow the format: file. Please review your input."}
WalkthroughPopulates fileName in CreateTranscriptionsReq.of(File) by setting it from file.getName() alongside the existing file assignment. No public API signatures changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java (1)
39-41: PopulatefileNameinof(String filePath)for consistencyCallers of
CreateTranscriptionsReq.of(String)currently omitfileName, which can trigger server-side validation failures. There’s one usage in the example code—no other production call sites or builder chains (setting onlyfilePath) were found—so derivingfileNameis safe and prevents future issues.Call site to update:
- example/src/main/java/example/audio/transcriptions/CreateTranscriptionExample.java:21
Suggested implementation:
public static CreateTranscriptionsReq of(String filePath) { if (filePath == null || filePath.isEmpty()) { throw new IllegalArgumentException("filePath must not be null/empty"); } String name = java.nio.file.Paths.get(filePath).getFileName().toString(); return CreateTranscriptionsReq.builder() .filePath(filePath) .fileName(name) .build(); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test (Java 17 on Windows)
- GitHub Check: test (Java 11 on Windows)
🔇 Additional comments (1)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java (1)
35-37: Good fix: setting fileName from File resolves the API's “invalid file” error.Populating
fileNameviafile.getName()inof(File)directly addresses the server-side validation issue without changing public APIs. Looks correct and low-risk.
| public static CreateTranscriptionsReq of(File file) { | ||
| return CreateTranscriptionsReq.builder().file(file).build(); | ||
| return CreateTranscriptionsReq.builder().file(file).fileName(file.getName()).build(); | ||
| } |
There was a problem hiding this comment.
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.