-
Notifications
You must be signed in to change notification settings - Fork 193
Add docs/JAVA.md with Java-specific guidance #2974
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||
| # Java Guidelines — S3Mock | ||||||
|
|
||||||
| Canonical reference for Java idioms, naming conventions, and code quality standards used across this project. | ||||||
|
|
||||||
| ## Style | ||||||
|
|
||||||
| Java code follows the **[Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)** enforced by Checkstyle (`etc/checkstyle.xml`). | ||||||
|
|
||||||
| Key rules: | ||||||
| - **Indentation**: 2 spaces (no tabs) | ||||||
| - **Line length**: 120 characters maximum | ||||||
| - **Braces**: Always use braces for `if`, `for`, `while`, `do` blocks | ||||||
| - **Imports**: Static imports first, then third-party packages; alphabetical within groups; no wildcard imports | ||||||
|
|
||||||
| ## Modern Java Idioms | ||||||
|
|
||||||
| ### Local Type Inference | ||||||
| - Use `var` for local variables when the type is clear from context: | ||||||
| ```java | ||||||
| var uploadFile = new File(UPLOAD_FILE_NAME); | ||||||
| var response = s3Client.getObject(...); | ||||||
| ``` | ||||||
| - Avoid `var` when the inferred type would be ambiguous or unclear | ||||||
|
|
||||||
| ### Collections | ||||||
| - `list.size() == 0` / `list.size() > 0` → `list.isEmpty()` / `!list.isEmpty()` | ||||||
| - Use `List.of(...)`, `Map.of(...)` for immutable collections instead of `Collections.unmodifiableList(...)` | ||||||
| - Prefer streams over explicit loops for transformations: | ||||||
| ```java | ||||||
| buckets.stream().map(Bucket::name).collect(Collectors.toSet()) | ||||||
|
||||||
| buckets.stream().map(Bucket::name).collect(Collectors.toSet()) | |
| buckets.stream().map(Bucket::name).collect(Collectors.toSet()); |
Copilot
AI
Feb 25, 2026
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.
The anti-patterns table is not valid Markdown because the rows start with || instead of |. This will render incorrectly on GitHub; use a single leading pipe for each row (header, separator, and body).
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.
The import-order guidance here doesn’t match the enforced Checkstyle config:
CustomImportOrderis configured asSTATIC###THIRD_PARTY_PACKAGE, which effectively means “static imports first, then all non-static imports” (no separate standard/third-party grouping). Consider rewording this bullet to reflect the actual rule to avoid confusion.