[ZEPPELIN-6247] Fix flag parsing bug in FileInterpreter#4976
Merged
Conversation
Fixed a bug where the dash character (-) was incorrectly included as a flag when parsing command arguments. Now only the actual flag characters after the dash are added to the flags set. Added unit tests to verify the correct parsing behavior.
Reamer
requested changes
Jul 16, 2025
Reamer
left a comment
Contributor
There was a problem hiding this comment.
LGTM, but please create a JIRA ticket for this.
Contributor
Author
|
@Reamer Thank you for the review! I've created a JIRA ticket as requested: ZEPPELIN-6247 I'll update the PR title to include the JIRA issue number. |
Contributor
|
@renechoi Two Checkstyle errors |
Fixed two checkstyle violations: - Added newline at end of file (NewlineAtEndOfFile rule) - Removed redundant 'public' modifier from inner class constructor (RedundantModifier rule)
Contributor
Author
|
@Reamer Thank you for catching those checkstyle errors! I've fixed both issues:
The changes have been applied and the code should now pass all checkstyle checks. |
Reamer
approved these changes
Jul 21, 2025
Contributor
|
Let's wait for CI. |
asf-gitbox-commits
pushed a commit
that referenced
this pull request
Jul 21, 2025
# [MINOR] Fix flag parsing bug in FileInterpreter ## What is this PR for? This PR fixes a bug in the `FileInterpreter` class where the dash character (`-`) was incorrectly included as a flag when parsing command arguments. ## What type of PR is it? Bug Fix ## What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-6247 ## How should this be tested? 1. Run the new unit tests: `FileInterpreterTest.java` 2. Verify that flag parsing works correctly: - Command: `ls -l` should only have flag `'l'`, not `'-'` and `'l'` - Command: `ls -lah` should have flags `'l'`, `'a'`, `'h'`, without `'-'` ## Screenshots (if appropriate) N/A ## Questions: * Does the license files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No ## Description ### Problem The current implementation of `parseArg()` method in `FileInterpreter.java` incorrectly includes the dash character as a flag: ```java // Before (line 73) for (int i = 0; i < arg.length(); i++) { ``` When parsing `-l`, this adds both `'-'` and `'l'` to the flags HashSet. ### Solution Start the loop from index 1 to skip the dash character: ```java // After for (int i = 1; i < arg.length(); i++) { ``` ### Impact Analysis - **Current behavior is not affected** because the existing code (`HDFSFileInterpreter`) only checks for specific flag characters like `'l'` and `'h'` - However, this is a **correctness issue** that could cause problems in future implementations - The fix ensures that only actual flag characters are stored in the flags set ### Test Coverage Added comprehensive unit tests in `FileInterpreterTest.java` to verify: - Single flags (`-l`) - Multiple flags (`-la`, `-lah`) - Separate flags (`-l -h`) - Edge cases (empty flag `-`) - Verification that dash is not included in the flags set Closes #4976 from renechoi/fix-fileinterpreter-flag-parsing. Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com> (cherry picked from commit 1a66333) Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com>
Contributor
|
Merged into master and branch-0.12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[MINOR] Fix flag parsing bug in FileInterpreter
What is this PR for?
This PR fixes a bug in the
FileInterpreterclass where the dash character (-) was incorrectly included as a flag when parsing command arguments.What type of PR is it?
Bug Fix
What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-6247
How should this be tested?
FileInterpreterTest.javals -lshould only have flag'l', not'-'and'l'ls -lahshould have flags'l','a','h', without'-'Screenshots (if appropriate)
N/A
Questions:
Description
Problem
The current implementation of
parseArg()method inFileInterpreter.javaincorrectly includes the dash character as a flag:When parsing
-l, this adds both'-'and'l'to the flags HashSet.Solution
Start the loop from index 1 to skip the dash character:
Impact Analysis
HDFSFileInterpreter) only checks for specific flag characters like'l'and'h'Test Coverage
Added comprehensive unit tests in
FileInterpreterTest.javato verify:-l)-la,-lah)-l -h)-)