content(blog): add Railway-Oriented Programming in Java post#59
Conversation
Introduce a new article covering the ROP pattern using pure Java: two-track Result<T,E> type, flatMap-based pipeline composition, structured error types with sealed interfaces, fail-fast vs accumulating validation, and a full user-registration example.
📝 WalkthroughWalkthroughA new blog article introducing Railway-Oriented Programming (ROP) in Java is added, demonstrating error handling using sealed Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@site/src/data/blog/railway-oriented-programming-in-java.md`:
- Line 357: The snippet calls User.anonymous() but that static factory is not
defined, so either add a clear definition on the User type (e.g., a static
method User.anonymous() returning a default/guest User) or replace the call site
result.getOrElse(User.anonymous()) with an inline fallback instance (e.g.,
result.getOrElse(new User(...)) or result.getOrElse(User.guest()) if you prefer
a different name); update the User class to include the chosen factory name
(anonymous() or guest()) so the example is self-contained and compiles.
- Around line 54-58: The markdown fenced block containing the railway diagram
(the block starting with the lines "input ──[step1]──[step2]──[step3]──▶
Success(result)" and its following lines) lacks a language tag and triggers
MD040; update that fence to include a language hint (e.g., add "text" after the
opening triple backticks: ```text) so the linter recognizes it as a code/diagram
block.
- Around line 276-284: The hashPassword function currently uses
req.password().hashCode() which is unsafe; replace the simplified hashing line
in hashPassword (the creation of the "hashed" variable and its "bcrypt:" prefix)
with a call to a real password-hashing library (e.g., BCrypt/Argon2/PBKDF2) that
produces a salted, slow hash, and return that value in the new
RegistrationRequest; ensure exceptions from the hashing library are caught and
wrapped in RegistrationError.StorageFailure as currently done. If you must keep
a doc-only example, instead add a clear, prominent “never use in production —
example only” warning comment directly above hashPassword and change the
placeholder to explicitly indicate it’s non-functional rather than showing
req.password().hashCode().
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 038d715e-a77f-4867-bb75-bd244e23b747
📒 Files selected for processing (1)
site/src/data/blog/railway-oriented-programming-in-java.md
| ``` | ||
| input ──[step1]──[step2]──[step3]──▶ Success(result) | ||
| │ | ||
| └──────────────────▶ Failure(error) | ||
| ``` |
There was a problem hiding this comment.
Add a language hint to the railway diagram code fence.
The fenced block is missing a language tag, which triggers markdown linting (MD040).
Suggested fix
-```
+```text
input ──[step1]──[step2]──[step3]──▶ Success(result)
│
└──────────────────▶ Failure(error)</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
```suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.21.0)
[warning] 54-54: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@site/src/data/blog/railway-oriented-programming-in-java.md` around lines 54 -
58, The markdown fenced block containing the railway diagram (the block starting
with the lines "input ──[step1]──[step2]──[step3]──▶ Success(result)" and its
following lines) lacks a language tag and triggers MD040; update that fence to
include a language hint (e.g., add "text" after the opening triple backticks:
```text) so the linter recognizes it as a code/diagram block.
| public static Result<RegistrationRequest, RegistrationError> hashPassword( | ||
| RegistrationRequest req | ||
| ) { | ||
| try { | ||
| String hashed = "bcrypt:" + req.password().hashCode(); // simplified | ||
| return Result.ok(new RegistrationRequest(req.email(), req.name(), hashed)); | ||
| } catch (Exception e) { | ||
| return Result.err(new RegistrationError.StorageFailure("hashing failed: " + e.getMessage())); | ||
| } |
There was a problem hiding this comment.
Avoid demonstrating password hashing with hashCode().
Even with “simplified” wording, this is an unsafe pattern that readers may copy into production code. Use a real password-hashing example (BCrypt/Argon2/PBKDF2), or add an explicit “never use in production” warning directly above this line.
Suggested doc-safe adjustment
- // --- Password hashing (simulated) ---
+ // --- Password hashing (simulated; DO NOT use hashCode for real passwords) ---
...
- String hashed = "bcrypt:" + req.password().hashCode(); // simplified
+ String hashed = "<hashed-password-placeholder>"; // illustrative only🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@site/src/data/blog/railway-oriented-programming-in-java.md` around lines 276
- 284, The hashPassword function currently uses req.password().hashCode() which
is unsafe; replace the simplified hashing line in hashPassword (the creation of
the "hashed" variable and its "bcrypt:" prefix) with a call to a real
password-hashing library (e.g., BCrypt/Argon2/PBKDF2) that produces a salted,
slow hash, and return that value in the new RegistrationRequest; ensure
exceptions from the hashing library are caught and wrapped in
RegistrationError.StorageFailure as currently done. If you must keep a doc-only
example, instead add a clear, prominent “never use in production — example only”
warning comment directly above hashPassword and change the placeholder to
explicitly indicate it’s non-functional rather than showing
req.password().hashCode().
| ### `getOrElse` — extract with a fallback | ||
|
|
||
| ```java | ||
| User user = result.getOrElse(User.anonymous()); |
There was a problem hiding this comment.
User.anonymous() is undefined in the article snippets.
This makes the snippet non-self-contained for readers trying to copy and run it. Either define anonymous() in the User section or switch to an inline fallback instance.
Suggested fix
-User user = result.getOrElse(User.anonymous());
+User user = result.getOrElse(new User(0L, "[email protected]", "Anonymous", ""));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| User user = result.getOrElse(User.anonymous()); | |
| User user = result.getOrElse(new User(0L, "[email protected]", "Anonymous", "")); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@site/src/data/blog/railway-oriented-programming-in-java.md` at line 357, The
snippet calls User.anonymous() but that static factory is not defined, so either
add a clear definition on the User type (e.g., a static method User.anonymous()
returning a default/guest User) or replace the call site
result.getOrElse(User.anonymous()) with an inline fallback instance (e.g.,
result.getOrElse(new User(...)) or result.getOrElse(User.guest()) if you prefer
a different name); update the User class to include the chosen factory name
(anonymous() or guest()) so the example is self-contained and compiles.
|
|
Introduce a new article covering the ROP pattern using pure Java:
two-track Result<T,E> type, flatMap-based pipeline composition,
structured error types with sealed interfaces, fail-fast vs
accumulating validation, and a full user-registration example.
Pull Request
📌 Summary
Briefly describe the purpose of this pull request and what problem it solves.
✅ Checklist
Please check all that apply:
🔗 Related Issues
Closes #55
Fixes #[issue-number]
(Related but not closing: #[issue-number])
💬 Additional Notes
Any other context, screenshots, design decisions, or points to be reviewed carefully.
Summary by CodeRabbit