Fix for Array index out of bounds#806
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6cf2b1f07b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { | ||
| throw new IllegalArgumentException ("Missing value for argument: " + arg); | ||
| } | ||
| String value = args[++i]; |
There was a problem hiding this comment.
Reject missing option values before consuming next flag
Using String value = args[++i]; without checking whether args[i + 1] is itself another CLI flag causes a new parsing regression: if a value is omitted in the middle (for example --ip-address --serial-port COM3), --serial-port is consumed as the IP value and then skipped entirely, so serial_port is never parsed. This commit adds missing-value validation, so this case should also raise an IllegalArgumentException instead of silently swallowing the next option.
Useful? React with 👍 / 👎.
To fix this safely without changing intended behavior, validate that each option requiring a value actually has a following argument before accessing
args[i + 1]. The best minimal fix is:i + 1 >= args.length; if true, throw a clearIllegalArgumentException.String value = args[++i];) and assign/parse it per option.This avoids out-of-bounds access, improves error messages, and keeps existing parsing semantics.
All changes are in
java_package/brainflow/src/main/java/brainflow/examples/EEGMetrics.java, insideparse_args.Suggested fixes powered by Copilot Autofix. Review carefully before merging.