Skip to content

Fix broken Java literalEval implementation in concoredocker#231

Open
GaneshPatil7517 wants to merge 2 commits intoControlCore-Project:mainfrom
GaneshPatil7517:fix/java-literal-eval
Open

Fix broken Java literalEval implementation in concoredocker#231
GaneshPatil7517 wants to merge 2 commits intoControlCore-Project:mainfrom
GaneshPatil7517:fix/java-literal-eval

Conversation

@GaneshPatil7517
Copy link

Summary

The Java implementation of concoredocker was fundamentally broken.
literalEval() was implemented as a no-op returning an empty HashMap,
causing read(), write(), defaultMaxTime(), and initVal() to silently malfunction.

Fix

  • Implement proper Python-style literal parsing in literalEval()
    • Supports dicts: {'key': value}
    • Supports lists: [val1, val2]
    • Supports numbers, strings, booleans, None
  • Fix unchanged() to return boolean (was void)
  • Fix defaultMaxTime() to read actual integer value
  • Fix read() and write() to properly handle List types
  • Add simtime tracking to match Python semantics
  • Add TestLiteralEval.java with 15 test cases

Impact

  • Restores correctness of Java backend
  • Prevents silent data corruption
  • Aligns Java behavior with Python reference implementation

Fixes #228

Copilot AI review requested due to automatic review settings February 9, 2026 11:02
The Java implementation of concoredocker was fundamentally broken.
literalEval() was implemented as a stub returning an empty HashMap,
causing read(), write(), defaultMaxTime(), and initVal() to silently
malfunction.

Changes:
- Implement proper Python-style literal parsing in literalEval()
  - Supports dicts: {'key': value}
  - Supports lists: [val1, val2]
  - Supports numbers, strings, booleans, None
- Fix unchanged() to return boolean (was void)
- Fix defaultMaxTime() to read actual integer value
- Fix read() and write() to properly handle List types
- Add simtime tracking to match Python semantics
- Add TestLiteralEval.java with 15 test cases

Fixes ControlCore-Project#228
Copy link

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

Fixes the Java concoredocker backend to actually parse Python-style literals (previously a stub), restoring correct behavior for reading ports, writing ports, and maxtime/simtime handling to better match the Python reference.

Changes:

  • Implement a recursive-descent literalEval() in concoredocker.java (dict/list/number/string/bool/None).
  • Update defaultMaxTime(), read(), write(), initVal(), and unchanged() to use the parsed literals and track simtime.
  • Add a standalone Java test driver TestLiteralEval.java with multiple parsing test cases.

Reviewed changes

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

File Description
requirements.txt Adds pyzmq to match existing import zmq usage in the Python codebase.
concoredocker.java Replaces no-op literal parsing with a real parser and updates I/O helpers to use it.
TestLiteralEval.java Adds a basic test harness validating literalEval() behavior via reflection.

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

Changes based on PR review:
- Use double for simtime to preserve fractional values
- Change delay from 1ms to 1000ms (matches Python's time.sleep(1))
- Add maxRetries limit in read() to avoid infinite blocking
- Restore thread interrupt status in InterruptedException handlers
- Catch RuntimeException in defaultMaxTime() for parse errors
- Add try-catch in parseFileAsMap() with logging for malformed files
- Wrap parseDouble/parseLong in try-catch with clear exceptions
- Add toPythonLiteral() for proper serialization (True/False/None/strings)
- Improve error messages throughout

All changes align Java behavior with Python reference implementation.
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.

concoredocker.java is fundamentally broken — literalEval() always returns empty HashMap

1 participant