Skip to content

Validate resistor input before color encoding - #114

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-unchecked-input-in-resistor-encoder
Closed

Validate resistor input before color encoding#114
krotname wants to merge 1 commit into
mainfrom
codex/fix-unchecked-input-in-resistor-encoder

Conversation

@krotname

@krotname krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The public ResistorColorCodes2.encodeResistorColors accepted any string ending with " ohms" but did not validate the numeric token, allowing malformed, negative, or non-finite values to cause NumberFormatException or invalid enum indexes and crash the encoder.
  • Hardening was needed to keep behavior unchanged for valid kata inputs while rejecting untrusted or malformed values safely.

Description

  • Wrap the parsing/encoding flow in encodeResistorColors with a try/catch that returns an empty string for invalid inputs instead of propagating exceptions.
  • Add finite and bounds checks in encodeResistorOhms using Double.isFinite(tempValue) and a range check (tempValue < 10 || tempValue > 990_000_000) and throw IllegalArgumentException for values outside the supported 10 ohm to 990M ohm range.
  • Update ResistorColorCodes2Test to add regression assertions that encodeResistorColors returns "" for malformed and out-of-range inputs such as "abc ohms", "-1 ohms", and "1e309 ohms".
  • Files changed: src/main/java/kyu5/ResistorColorCodes2.java, src/test/java/kyu5/ResistorColorCodes2Test.java.

Testing

  • Ran mvn -q -Dtest=kyu5.ResistorColorCodes2Test test and the test class passed.
  • Ran full test suite with mvn -q test and the build/tests completed successfully.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe03ea6e25

ℹ️ 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".

Comment thread src/main/java/kyu5/ResistorColorCodes2.java
@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Закрываю как superseded by #116: изменения перенесены в одну проверенную ветку, все review findings учтены; локальный mvn verify прошёл полностью.

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-unchecked-input-in-resistor-encoder branch August 1, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant