{"record":{"id":"89013c6cd3a2c091","repo":"EnterpriseQualityCoding/FizzBuzzEnterpriseEdition","slug":"the-integers-could-not-be-compared","errorCode":null,"errorMessage":"The integers could not be compared.","messagePattern":"The integers could not be compared\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/integercomparator/ThreeWayIntegerComparator.java","lineNumber":29,"sourceCode":"public final class ThreeWayIntegerComparator {\n\n\tprivate ThreeWayIntegerComparator() {}\n\n\t/**\n\t * @param nFirstInteger int\n\t * @param nSecondInteger int\n\t * @return ThreeWayIntegerComparisonResult\n\t */\n\tpublic static ThreeWayIntegerComparisonResult Compare(final int nFirstInteger, final int nSecondInteger) {\n\t\tif (nFirstInteger == nSecondInteger) {\n\t\t\treturn ThreeWayIntegerComparisonResult.FirstEqualsSecond;\n\t\t} else if (nFirstInteger < nSecondInteger) {\n\t\t\treturn ThreeWayIntegerComparisonResult.FirstIsLessThanSecond;\n\t\t} else if (nFirstInteger > nSecondInteger) {\n\t\t\treturn ThreeWayIntegerComparisonResult.FirstIsGreaterThanSecond;\n\t\t} else {\n\t\t\t// If the integers cannot be compared, then something is seriously wrong with the numbers.\n\t\t\tthrow new UnsupportedOperationException(Constants.THE_INTEGERS_COULD_NOT_BE_COMPARED);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":11,"sourceCodeEnd":34,"githubUrl":"https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition/blob/4922c077c07a3744ae67ee8a932786f15bf57411/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/integercomparator/ThreeWayIntegerComparator.java#L11-L34","documentation":"ThreeWayIntegerComparator.Compare orders two ints through an exhaustive if/else chain: equal, less-than, greater-than — and the final else throws UnsupportedOperationException with 'The integers could not be compared'. For the primitive type int those three branches are mathematically exhaustive, so the throw is dead defensive code (a total order always exists for ints). It can never fire with valid Java semantics; its presence is part of the codebase's satirical over-engineering.","triggerScenarios":"Effectively unreachable: Compare(int, int) always returns from the first three branches for any int pair, including MIN_VALUE/MAX_VALUE. It would only be observable if the code were ported to non-primitive numeric types lacking a total order (e.g. float/double NaN, where none of ==, <, > holds), or if the comparison chain were modified to introduce a gap between the conditions.","commonSituations":"Developers see the string in logs or test-coverage reports and assume a real defect; or the pattern is copy-pasted to Double.compare-style logic where NaN genuinely fails all three comparisons and the throw becomes live. Also hit when someone 'simplifies' one of the chained conditions (e.g. changing < to <= incorrectly), making some inputs fall through to the else.","solutions":["Recognize it is unreachable for ints — no action is needed for correct inputs; do not add defensive handling around it.","If porting this comparator to double/float, handle NaN before the chain: if (Double.isNaN(a) || Double.isNaN(b)) throw new IllegalArgumentException(...).","If a code change introduced fall-through, restore the exhaustive == / < / > chain exactly so the else remains dead.","For test coverage of the branch, delete the else or extract it with a comment marking it unreachable — keeping it only aids the satire."],"exampleFix":"// before (NaN port makes the throw reachable)\npublic static ThreeWayIntegerComparisonResult Compare(double a, double b) {\n    if (a == b) return FirstEqualsSecond;\n    else if (a < b) return FirstIsLessThanSecond;\n    else if (a > b) return FirstIsGreaterThanSecond;\n    else throw new UnsupportedOperationException(\"The integers could not be compared.\");\n}\n\n// after (validate NaN up front, keep total order)\npublic static ThreeWayIntegerComparisonResult Compare(double a, double b) {\n    if (Double.isNaN(a) || Double.isNaN(b)) {\n        throw new IllegalArgumentException(\"NaN is not comparable\");\n    }\n    if (a < b) return FirstIsLessThanSecond;\n    if (a > b) return FirstIsGreaterThanSecond;\n    return FirstEqualsSecond;\n}","handlingStrategy":"validation","validationCode":"// For int: nothing to validate — the branch is unreachable.\n// If porting to double/float, validate before Compare:\nif (Double.isNaN(a) || Double.isNaN(b)) {\n    throw new IllegalArgumentException(\"NaN inputs are not comparable\");\n}\nfinal ThreeWayIntegerComparisonResult r = ThreeWayIntegerComparator.Compare(a, b);","typeGuard":"// Narrow numeric inputs to totally-ordered values before comparing\nstatic boolean isTotallyOrdered(final double v) {\n    return !Double.isNaN(v) && !Double.isInfinite(v);\n}\n\nif (isTotallyOrdered(a) && isTotallyOrdered(b)) {\n    // safe: all of ==, <, > will decide\n}","tryCatchPattern":"// Normally unnecessary; only around modified/ported comparators\ntry {\n    final ThreeWayIntegerComparisonResult r = ThreeWayIntegerComparator.Compare(x, y);\n} catch (final UnsupportedOperationException e) {\n    if (!\"The integers could not be compared.\".equals(e.getMessage())) throw e;\n    throw new IllegalStateException(\"Comparator contract violated — non-int inputs or modified chain\", e);\n}","preventionTips":["Do not add handling around Compare(int, int) — for primitives the throw is unreachable dead code.","Never port this if/else chain to double/float without a NaN pre-check; NaN defeats ==, <, and > simultaneously.","When editing the comparison chain, keep == / < / > exactly exhaustive; any changed operator can silently make the else reachable.","Use Integer.compare(a, b) (JDK 7+) instead of hand-rolled chains — it is total by construction and cannot throw."],"tags":["java","unreachable-code","defensive-programming","comparator","fizzbuzz-enterprise"],"backgroundTag":null,"analyzedSha":"4922c077c07a3744ae67ee8a932786f15bf57411","analyzedAt":"2026-08-14T10:51:26.690Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}