Skip to content

fix(java): rewrite literalEval() with recursive descent parser#252

Merged
pradeeban merged 2 commits intoControlCore-Project:devfrom
GaneshPatil7517:fix/java-literal-eval-only
Feb 11, 2026
Merged

fix(java): rewrite literalEval() with recursive descent parser#252
pradeeban merged 2 commits intoControlCore-Project:devfrom
GaneshPatil7517:fix/java-literal-eval-only

Conversation

@GaneshPatil7517
Copy link
Copy Markdown
Contributor

@GaneshPatil7517 GaneshPatil7517 commented Feb 11, 2026

This PR fixes #228 related to the literalEval() implementation in concoredocker.java.

The previous implementation was using String.split(","), which caused problems in several situations such as nested structures (like lists inside dictionaries), strings containing commas or colons, and cases with escape sequences. Because of this, some valid Python literals were not being parsed correctly.

To fix this, I replaced the logic with a recursive descent parser that can properly handle Python literal syntax. I also added an escapePythonString() method for correct string escaping and updated toPythonLiteral() so it uses Python values like True, False, and None.

Some additional fixes were also made:

  • read() now returns List<Object> and includes a retry mechanism
  • write() delay is changed to double instead of int, with separate catch blocks
  • simtime type is updated to double

I also added a test file TestLiteralEval.java with 49 test cases to verify different scenarios.

All 49 tests pass locally.

This PR contains only the Java files as requested:

  • concoredocker.java (fixed implementation)
  • TestLiteralEval.java (test suite)

Fixes #228

Fix ControlCore-Project#228: concoredocker.java literalEval() is fundamentally broken

The original implementation used String.split(",") which failed for:
- Nested structures (lists within dicts, etc.)
- Strings containing commas or colons
- Escape sequences in strings

Changes:
- Implement recursive descent parser for Python literal syntax
- Add escapePythonString() for proper string escaping
- Fix toPythonLiteral() to use Python True/False/None
- Fix read() to return List<Object> with max retries
- Fix write() delay to double (was int) with separate catch blocks
- Fix simtime to double type
- Add TestLiteralEval.java with 49 comprehensive tests

All tests pass.
Copilot AI review requested due to automatic review settings February 11, 2026 19:14
@GaneshPatil7517
Copy link
Copy Markdown
Contributor Author

GaneshPatil7517 commented Feb 11, 2026

Hey @pradeeban

CI Failures Note

The CI failures are not caused by this PR's Java changes - they are pre-existing issues in the \dev\ branch:

  1. lint-and-test: \ModuleNotFoundError: No module named 'click'\ - The
    equirements-ci.txt\ is missing the \click\ dependency needed by \ ests/test_cli.py\

  2. test (3.11): \ est_run_command_from_project_dir\ assertion failure (\1 != 0) - This is an unrelated test failure in the existing test suite

The Java changes in this PR are correct and all 49 Java tests pass locally. These CI issues exist independently of this PR and would need to be fixed in a separate PR targeting the CI/Python files.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the Java concoredocker implementation by replacing the previously broken literalEval() behavior with a recursive-descent parser for Python-style literals, and updates related I/O handling to better match the Python runtime behavior.

Changes:

  • Replaced literalEval() with a recursive descent parser supporting nested dict/list/tuple, numbers, strings, booleans, and None.
  • Updated read/write helpers (retry behavior, delay handling, simtime as double) and added Python-literal serialization helpers.
  • Added a standalone Java test program TestLiteralEval.java to exercise the new parser.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
concoredocker.java Implements the new literal parser, updates simtime/delay handling, and revises read/write parsing/serialization behavior.
TestLiteralEval.java Adds a standalone test runner validating core parsing behaviors and a subset of edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GaneshPatil7517
Copy link
Copy Markdown
Contributor Author

Update: Created PR #253 to fix the CI dependency issues separately. Once that PR is merged, the CI should pass for this Java-only PR.

- Remove s += initstr on max-retries and parse-error paths in read()
  (accumulator should not include default when returning it)
- Add dict key validation: throw if key is not a non-null String
- Use explicit UTF-8 charset in parseFile() and sparams reading
- Align sparams parsing with Python parse_params logic:
  try literalEval first if input looks like dict literal
- Update test comment to reflect actual coverage
- Remove unused list creation in testRoundTripSerialization()
- Add test for non-string dict key validation

All 50 tests pass.
@pradeeban pradeeban merged commit 9c5362a into ControlCore-Project:dev Feb 11, 2026
1 of 6 checks passed
@pradeeban
Copy link
Copy Markdown
Member

Thanks, merged both PRs now.

@GaneshPatil7517
Copy link
Copy Markdown
Contributor Author

thank you so much @pradeeban its really boosting my confidence....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants