Skip to content

Harden CLI demos against invalid input and validate HashTable size#16

Merged
Nullkernel merged 1 commit intomainfrom
codex/improve-command-line-demo-reliability
Apr 5, 2026
Merged

Harden CLI demos against invalid input and validate HashTable size#16
Nullkernel merged 1 commit intomainfrom
codex/improve-command-line-demo-reliability

Conversation

@Nullkernel
Copy link
Copy Markdown
Owner

Motivation

  • CLI demo programs used new Scanner/nextInt in many places and would crash or exit abruptly on non-integer input.
  • The HashTable initializer allocated the table without validating size > 0, which could cause runtime errors.
  • Provide a small, consistent input-recovery UX so demos are more reliable for real users.

Description

  • Changed HashTable.initialise() to initialise(Scanner) and added readInt/readPositiveInt helpers plus a INVALID_INT_MESSAGE constant to validate size > 0 before allocating the table in Data-Structures/HashTable.java.
  • Replaced ad-hoc nextInt() calls with guarded reads in Data-Structures/Stack.java by adding readInt/readPositiveInt helpers and using them for menu choices and size/value inputs.
  • Added the same guarded input helpers and positive-size validation to Data-Structures/Queue/Queue.java and Data-Structures/Queue/CircularQueue.java, and standardized invalid-choice messages across the updated demos.
  • Ensured Scanner instances are used consistently (single Scanner passed into initialise for HashTable) and closed at program exit where appropriate.

Testing

  • Compiled the modified demos with javac Data-Structures/HashTable.java and javac Data-Structures/Stack.java and javac Data-Structures/Queue/Queue.java and javac Data-Structures/Queue/CircularQueue.java, and compilation succeeded for all four files.

Codex Task

@Nullkernel Nullkernel merged commit 17c1021 into main Apr 5, 2026
1 check passed
@Nullkernel Nullkernel deleted the codex/improve-command-line-demo-reliability branch April 6, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant