feat: add convenience constructors to FileWithBytes#706
feat: add convenience constructors to FileWithBytes#706ehsavoie wants to merge 1 commit intoa2aproject:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces three new convenience constructors to the FileWithBytes record, allowing direct creation from File, Path, or byte[] inputs, with internal Base64 encoding, which significantly simplifies the API for callers. While these changes improve usability and are accompanied by comprehensive unit tests, they introduce a potential Denial of Service (DoS) vulnerability. The constructors read entire files into memory without size limits, which could lead to an OutOfMemoryError when processing large files. It is recommended to implement file size validation in these constructors to mitigate this risk. Additionally, an unnecessary throws IOException declaration in one constructor should be removed to improve API accuracy, aligning with best practices for Javadoc and API contract integrity.
jmesnil
left a comment
There was a problem hiding this comment.
Gemini remark is good but its solution is not :)
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces convenience constructors to the FileWithBytes class, allowing direct creation from File, Path, or byte[] inputs with internal base64 encoding, simplifying the API for callers. It also utilizes lazy loading for file content. However, the implementation has critical security and robustness concerns. The internal source field leaks server-side file paths during JSON serialization because it is not marked as transient. Furthermore, the byte[] constructor does not clone the input array, breaking the class's immutability, and there's a potential for service crashes due to broken deserialization logic in the associated JsonUtil adapters. Finally, attention is needed regarding the equals and hashCode contract and documentation consistency.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors FileWithBytes from a record to a class, introducing convenience constructors for File, Path, and byte[] sources. The implementation includes lazy loading of file content with soft-reference caching, which is a great improvement for performance and memory management. The custom Gson TypeAdapter correctly prevents leaking internal fields during serialization, and the new tests are comprehensive.
I've found one minor issue regarding inconsistent validation in one of the new constructors, which I've detailed in a specific comment.
Add three constructors to FileWithBytes that accept a File, a Path, or a byte[] and handle base64 encoding internally, removing the need for callers to encode content before construction. Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Add three constructors to FileWithBytes that accept a File, a Path, or a byte[] and handle base64 encoding internally, removing the need for callers to encode content before construction.
Fixes #702 🦕