Skip to content

Conversation

@HossamSaberr
Copy link
Contributor

@HossamSaberr HossamSaberr commented Oct 28, 2025

close #52

Summary by CodeRabbit

  • Chores

    • Build configuration updated to enable generated accessor processing during compilation.
  • Refactor

    • Reduced boilerplate by consolidating accessors in the shell context.
    • Added an environment-variables store with public set/get methods.
    • Collections (history, aliases, env vars) now return defensive copies to protect internal state.

@github-actions
Copy link

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

@coderabbitai
Copy link

coderabbitai bot commented Oct 28, 2025

Warning

Rate limit exceeded

@HossamSaberr has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7147345 and d232cbd.

📒 Files selected for processing (1)
  • src/main/java/com/mycmd/ShellContext.java (5 hunks)

Walkthrough

Added Lombok to the Maven build and refactored ShellContext to use Lombok-generated accessors; introduced a final envVars map with setEnvVar/getEnvVar; replaced explicit currentDir getters/setters with Lombok annotations and added defensive-copy getters for history, aliases, and envVars.

Changes

Cohort / File(s) Summary
Build configuration
pom.xml
Added dependency org.projectlombok:lombok:1.18.32 (scope: provided) and configured maven-compiler-plugin:3.11.0 with annotationProcessorPaths including Lombok to enable annotation processing.
Lombok refactor — Shell context
src/main/java/com/mycmd/ShellContext.java
Applied Lombok annotations (@Getter at class level; @Setter and @NonNull on currentDir); removed explicit getCurrentDir/setCurrentDir; added private final Map<String,String> envVars = new HashMap<>(); plus setEnvVar(String,String) and getEnvVar(String); added defensive-copy getters for history, aliases, and envVars.

Sequence Diagram(s)

(omitted — changes are structural/annotation-based and do not modify runtime control flow)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Check all call sites for getCurrentDir/setCurrentDir use to ensure Lombok-generated methods preserve behavior and nullability.
  • Review defensive-copy implementations for getHistory(), getAliases(), and getEnvVars() for immutability and concurrency concerns.
  • Verify Maven compiler annotation-processor configuration works in CI/IDE and that Lombok is not accidentally excluded from builds.

Poem

🐰 I nibble boilerplate away,

Beans now sprout with less display.
Env-vars snug in tidy rows,
Lombok lends its gentle prose.
Hop on — the codebase softly glows.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The PR includes changes that extend beyond the core objective stated in issue #52. While replacing manual accessors with Lombok annotations is in scope, the addition of a new envVars field with associated methods (getEnvVars, setEnvVar, getEnvVar) introduces new functionality not mentioned in the linked issue. Issue #52 focuses on reducing boilerplate by replacing existing getters and setters, not adding new fields and their accessors. This environmental variable management feature appears to be an out-of-scope enhancement bundled with the Lombok integration work. Either separate the envVars field and its accessor methods into a distinct PR focused on environment variable management, or provide justification for why this new functionality belongs in the Lombok integration PR. This will keep the changeset focused and make the intent of the work clearer.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Linked Issues Check ❓ Inconclusive The PR successfully introduces Lombok integration by adding the dependency to pom.xml with proper maven-compiler-plugin configuration [#52], and demonstrates its usage by applying @Getter and @Setter annotations to ShellContext.java while removing corresponding manual accessor methods [#52]. However, linked issue #52 explicitly states the goal is to reduce boilerplate "across multiple classes," yet only ShellContext.java is modified in this changeset. It is unclear whether this represents a complete resolution of the issue or a partial implementation addressing only one class as an initial step.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Feat/add lombok" clearly and directly describes the main change in this pull request—introducing Lombok to the project. It is concise, specific, and a teammate scanning the repository history would immediately understand that this PR adds Lombok support. The title accurately reflects the primary objective without noise or ambiguity.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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 (2)
src/main/java/com/mycmd/ShellContext.java (1)

20-21: Encapsulation improvement for envVars—expose only through safe immutable views and controlled mutators.

The class-level @Getter auto-generates a public getEnvVars() that exposes the mutable Map directly, allowing external code to mutate internal state via getEnvVars().put() or getEnvVars().clear(). One existing read-only usage (SetCommand.java:13) will remain safe with an unmodifiable view; no code mutations are required.

Apply the fix:

@@
-    @Getter 
+    @Getter(lombok.AccessLevel.NONE) 
     @Setter 
     public class ShellContext {

Add safe accessors:

+    public Map<String, String> getEnvVars() {
+        return Collections.unmodifiableMap(envVars);
+    }
+
+    public void setEnvVar(String key, String value) {
+        Objects.requireNonNull(key, "key");
+        Objects.requireNonNull(value, "value");
+        envVars.put(key, value);
+    }
+
+    public void removeEnvVar(String key) {
+        envVars.remove(key);
+    }

Add imports:

+import java.util.Collections;
+import java.util.Objects;
+import lombok.AccessLevel;
pom.xml (1)

20-27: Update Lombok to latest stable 1.18.42 and wire via maven-compiler-plugin annotationProcessorPaths for consistent CI/IDE builds.

Lombok 1.18.32 is compatible with Java 17 and has no known CVEs. However, the latest stable version is 1.18.42 (released Sep 18, 2025). Configuring Lombok under maven-compiler-plugin's annotationProcessorPaths ensures consistent behavior across IDE and CI builds. The suggested maven-compiler-plugin version 3.13.0 supports this configuration and works with Java 17.

Apply this (additions only) to pom.xml:

*** pom.xml
@@
   <properties>
     <maven.compiler.source>17</maven.compiler.source>
     <maven.compiler.target>17</maven.compiler.target>
+    <lombok.version>1.18.42</lombok.version>
   </properties>
@@
   <build>
     <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.13.0</version>
+        <configuration>
+          <release>17</release>
+          <annotationProcessorPaths>
+            <path>
+              <groupId>org.projectlombok</groupId>
+              <artifactId>lombok</artifactId>
+              <version>${lombok.version}</version>
+            </path>
+          </annotationProcessorPaths>
+        </configuration>
+      </plugin>
     </plugins>
   </build>

Optionally, drop Lombok from regular <dependencies> and rely solely on annotationProcessorPaths, or keep it as provided for IDE support—both patterns are supported.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f5fb4f and ffa2d92.

📒 Files selected for processing (2)
  • pom.xml (2 hunks)
  • src/main/java/com/mycmd/ShellContext.java (2 hunks)
🔇 Additional comments (1)
src/main/java/com/mycmd/ShellContext.java (1)

3-4: Lombok imports look fine.
No issues; proceed.

@github-actions
Copy link

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

@github-actions
Copy link

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5376f2e and 5b893e7.

📒 Files selected for processing (2)
  • pom.xml (2 hunks)
  • src/main/java/com/mycmd/ShellContext.java (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pom.xml
🧰 Additional context used
🪛 GitHub Actions: ⚙️ Java CI Build
src/main/java/com/mycmd/ShellContext.java

[error] 46-46: Override annotation error: method does not override or implement a method from a supertype.


[error] 51-51: Override annotation error: method does not override or implement a method from a supertype.


[error] 56-56: Override annotation error: method does not override or implement a method from a supertype.

🔇 Additional comments (9)
src/main/java/com/mycmd/ShellContext.java (9)

3-5: LGTM! Lombok imports are correct.

The Lombok imports are properly added and all are used in the class.


13-15: LGTM! Field-level annotations correctly applied.

The field-level @Setter and @NonNull on currentDir correctly implement the past review suggestion, generating setCurrentDir(File) with null checks while avoiding unwanted setters on collection fields.


24-24: LGTM! Environment variable field properly initialized.

The envVars field is correctly declared as final with inline initialization, preventing reassignment while allowing controlled mutations through dedicated accessor methods.


26-33: LGTM! Constructor properly initializes all fields.

The constructor correctly initializes all fields and loads persisted aliases.


35-41: LGTM! History management correctly implemented.

The method properly adds commands to both history lists and enforces the maximum history limit.


62-83: LGTM! Alias and history management methods are correct.

All methods properly manage aliases and history with appropriate persistence calls.


85-92: LGTM! Environment variable accessors correctly implemented.

The setEnvVar and getEnvVar methods provide controlled access to the environment variables map with appropriate encapsulation.


95-133: LGTM! Alias persistence methods are well-implemented.

Both loadAliases() and saveAliases() properly handle file I/O with try-with-resources, appropriate error handling, and user-friendly warning messages.


135-149: LGTM! Path resolution logic correctly implemented.

The resolvePath method properly handles null, empty, absolute, and relative paths with appropriate defaults.

import java.util.*;
import java.time.Instant;

@Getter
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix: Class-level @Getter conflicts with custom getter implementations.

The class-level @Getter generates getters for all fields, but you're attempting to provide custom implementations for getHistory(), getAliases(), and getEnvVars() that return defensive copies. This approach causes the @Override compilation errors on lines 46, 51, and 56 because you cannot override methods generated in the same class.

Solution: Exclude specific fields from the class-level @Getter by annotating them with @Getter(AccessLevel.NONE), then provide your custom getters without @Override.

Apply this diff:

+import lombok.AccessLevel;
+
 @Getter 
 public class ShellContext {
     
     @Setter
     @NonNull 
     private File currentDir;
     
+    @Getter(AccessLevel.NONE)
     private List<String> history;
+    @Getter(AccessLevel.NONE)
     private Map<String, String> aliases;
     private static final String ALIAS_FILE = ".mycmd_aliases";
     private static final int MAX_HISTORY = 100;
     private final List<String> commandHistory;
     private final Instant startTime;
 
+    @Getter(AccessLevel.NONE)
     private final Map<String, String> envVars = new HashMap<>();

Then remove the @Override annotations from lines 46, 51, and 56 (see separate comments below).

🤖 Prompt for AI Agents
In src/main/java/com/mycmd/ShellContext.java around line 10, the class-level
@Getter generates getters for all fields which conflicts with your custom
getHistory(), getAliases(), and getEnvVars() methods; annotate the specific
fields (history, aliases, envVars) with @Getter(AccessLevel.NONE) to exclude
them from Lombok generation and keep the class-level @Getter for others, then
remove the @Override annotations from your custom getter methods on lines ~46,
~51, and ~56 so they become regular methods returning defensive copies.

Comment on lines 43 to 49
/** * OVERRIDES Lombok's generated getter to return a DEFENSIVE COPY
* to prevent external code from modifying the shell directly.
*/
@Override
public List<String> getHistory() {
return new ArrayList<>(history);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Remove invalid @OverRide annotation (compilation error).

Line 46's @Override annotation causes a compilation error because Lombok generates getHistory() in the same class, not in a supertype. You cannot override a method generated in the same class.

Fix: After applying the @Getter(AccessLevel.NONE) fix on the history field (see comment on line 10), remove the @Override annotation and update the misleading comment:

-    /** * OVERRIDES Lombok's generated getter to return a DEFENSIVE COPY 
-     * to prevent external code from modifying the shell directly.
+    /**
+     * Returns a defensive copy of the command history
+     * to prevent external code from modifying it directly.
      */
-    @Override
     public List<String> getHistory() {
         return new ArrayList<>(history);
     }
📝 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.

Suggested change
/** * OVERRIDES Lombok's generated getter to return a DEFENSIVE COPY
* to prevent external code from modifying the shell directly.
*/
@Override
public List<String> getHistory() {
return new ArrayList<>(history);
}
/**
* Returns a defensive copy of the command history
* to prevent external code from modifying it directly.
*/
public List<String> getHistory() {
return new ArrayList<>(history);
}
🧰 Tools
🪛 GitHub Actions: ⚙️ Java CI Build

[error] 46-46: Override annotation error: method does not override or implement a method from a supertype.

🤖 Prompt for AI Agents
In src/main/java/com/mycmd/ShellContext.java around lines 43 to 49, remove the
invalid @Override annotation from the getHistory() method (it causes a
compilation error because Lombok generates the getter in the same class), and
update the Javadoc to remove the "OVERRIDES" wording — instead document that
this is a custom getter that returns a defensive copy to prevent external
mutation; keep the method body returning new ArrayList<>(history) and ensure you
have previously added @Getter(AccessLevel.NONE) to the history field so Lombok
does not generate a conflicting getter.

@github-actions
Copy link

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
src/main/java/com/mycmd/ShellContext.java (2)

10-18: Apply the previously recommended fix: add @Getter(AccessLevel.NONE) for fields with custom getters.

The past review (marked as "✅ Addressed") recommended annotating history and aliases fields with @Getter(AccessLevel.NONE) to explicitly exclude them from Lombok's class-level getter generation, since you provide custom defensive-copy getters. This recommendation was not applied in the current code.

While Lombok may skip generation when a method exists, explicit exclusion makes the intent clear and follows the agreed-upon fix.

Apply this diff:

+import lombok.AccessLevel;
+
 @Getter 
 public class ShellContext {
     
     @Setter
     @NonNull 
     private File currentDir;
     
+    @Getter(AccessLevel.NONE)
     private List<String> history;
+    @Getter(AccessLevel.NONE)
     private Map<String, String> aliases;

45-48: Fix incorrect comment: getHistory() returns a List, not a Map.

The comment on line 45 states "Returns a DEFENSIVE COPY instead of the raw Map" but getHistory() returns a List<String>, not a Map.

Apply this diff:

-    /** * RETAINED FOR SAFETY: Returns a DEFENSIVE COPY instead of the raw Map. */
+    /** Returns a defensive copy of the command history to prevent external modification. */
     public List<String> getHistory() {
         return new ArrayList<>(history);
     }
🧹 Nitpick comments (1)
src/main/java/com/mycmd/ShellContext.java (1)

81-87: Consider adding null checks for environment variable accessors.

The setEnvVar and getEnvVar methods provide straightforward access to environment variables. Consider adding null checks or validation if null keys/values should not be allowed. The current implementation permits null keys and values via HashMap's default behavior.

Example with validation:

 public void setEnvVar(String key, String value) {
+    if (key == null || key.trim().isEmpty()) {
+        throw new IllegalArgumentException("Environment variable key cannot be null or empty");
+    }
     envVars.put(key, value);
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b893e7 and be7db4c.

📒 Files selected for processing (1)
  • src/main/java/com/mycmd/ShellContext.java (4 hunks)
🔇 Additional comments (2)
src/main/java/com/mycmd/ShellContext.java (2)

3-5: LGTM: Lombok imports are correct.

The Lombok annotation imports are appropriate for the features used in this class.


50-56: Good practice: defensive copies protect internal state.

The custom getters for getAliases() and getEnvVars() correctly return defensive copies to prevent external code from modifying internal collections.

private final List<String> commandHistory;
private final Instant startTime;

private final Map<String, String> envVars = new HashMap<>();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add @Getter(AccessLevel.NONE) to the envVars field.

The envVars field has a custom getter at lines 54-56 that returns a defensive copy. Consistent with the recommendation for history and aliases, this field should also be annotated with @Getter(AccessLevel.NONE).

Apply this diff:

+    @Getter(AccessLevel.NONE)
     private final Map<String, String> envVars = new HashMap<>();
📝 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.

Suggested change
private final Map<String, String> envVars = new HashMap<>();
@Getter(AccessLevel.NONE)
private final Map<String, String> envVars = new HashMap<>();
🤖 Prompt for AI Agents
In src/main/java/com/mycmd/ShellContext.java around line 24, the envVars field
needs to prevent Lombok from generating a getter because a custom defensive-copy
getter already exists; add the annotation @Getter(AccessLevel.NONE) to the
private final Map<String, String> envVars = new HashMap<>(); and ensure
lombok.Getter and lombok.AccessLevel are imported (or existing imports include
them), so the generated getter is suppressed and the class uses the custom
getter at lines 54-56.

@github-actions
Copy link

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

@github-actions
Copy link

🚀 Hi @HossamSaberr!

Thank you for contributing to MyCMD. A maintainer will review your PR shortly. 🎉

@anshumanjadiya1102 anshumanjadiya1102 merged commit da25985 into Drive-for-Java:main Oct 29, 2025
4 checks passed
@anshumanjadiya1102 anshumanjadiya1102 added hacktoberfest-accepted This is for Hacktoberfest hacktoberfest This is for Hacktoberfest and removed needs-review labels Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from-fork hacktoberfest This is for Hacktoberfest hacktoberfest-accepted This is for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]

2 participants