{"record":{"id":"b71697de613bdced","repo":"prestodb/presto","slug":"array1-and-array2-cannot-be-null-and-should-have-s","errorCode":null,"errorMessage":"array1 and array2 cannot be null and should have same length","messagePattern":"array1 and array2 cannot be null and should have same length","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/BlockUtil.java","lineNumber":241,"sourceCode":"        for (int i = 0; i < positions.length; i++) {\n            int offsetStart = offsets[offsetBase + i];\n            int offsetEnd = offsets[offsetBase + i + 1];\n            if (positions[i]) {\n                used += (offsetEnd - offsetStart);\n                Arrays.fill(elementPositions, offsetStart, offsetEnd, true);\n            }\n        }\n        return used;\n    }\n\n    /**\n     * Returns <tt>true</tt> if the two specified arrays contain the same object in every position.\n     * Unlike the {@link Arrays#equals(Object[], Object[])} method, this method compares using reference equals.\n     */\n    static boolean arraySame(Object[] array1, Object[] array2)\n    {\n        if (array1 == null || array2 == null || array1.length != array2.length) {\n            throw new IllegalArgumentException(\"array1 and array2 cannot be null and should have same length\");\n        }\n\n        for (int i = 0; i < array1.length; i++) {\n            if (array1[i] != array2[i]) {\n                return false;\n            }\n        }\n        return true;\n    }\n\n    public static boolean internalPositionInRange(int internalPosition, int offset, int positionCount)\n    {\n        boolean withinRange = internalPosition >= offset && internalPosition < positionCount + offset;\n        assert withinRange : format(\"internalPosition %s is not within range [%s, %s)\", internalPosition, offset, positionCount + offset);\n        return withinRange;\n    }\n\n    static boolean[] appendNullToIsNullArray(@Nullable boolean[] isNull, int offsetBase, int positionCount)","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/BlockUtil.java#L223-L259","documentation":"BlockUtil.arraySame compares two Object[] arrays by reference identity at each position. It requires both arrays to be non-null and of equal length; if either is null or the lengths differ, the inputs are invalid for the comparison and the library throws this IllegalArgumentException instead of returning a value. It is a precondition check on the caller.","triggerScenarios":"Calling BlockUtil.arraySame(null, someArray), arraySame(someArray, null), or arraySame(a, b) where a.length != b.length. Typically triggered in block-cloning/dedup code paths that compare dictionaries or instance arrays of mismatched sizes.","commonSituations":"Passing a partially initialized or filtered-out array (null) into a comparison; comparing dictionary-encoded blocks whose dictionary arrays were rebuilt with different sizes; a bug in custom block implementations that supply arrays of differing lengths to the comparison helper.","solutions":["Validate inputs before calling: ensure both arrays are non-null and have the same length; return false or handle the mismatch yourself when lengths legitimately differ.","If lengths can legitimately differ, use a length check first and treat different lengths as 'not the same' rather than an error.","If you own the calling code, ensure the arrays come from the same logical source so sizes always match (e.g., dictionaries from blocks with identical position counts)."],"exampleFix":"// before\nboolean same = BlockUtil.arraySame(dict1, dict2);\n// after\nboolean same = (dict1 != null && dict2 != null && dict1.length == dict2.length)\n        && BlockUtil.arraySame(dict1, dict2);","handlingStrategy":"validation","validationCode":"if (array1 == null || array2 == null || array1.length != array2.length) {\n    // treat as not-same or handle explicitly; do not call arraySame\n    return false;\n}\nboolean same = BlockUtil.arraySame(array1, array2);","typeGuard":"boolean isComparable(Object[] a, Object[] b) {\n    return a != null && b != null && a.length == b.length;\n}","tryCatchPattern":"try {\n    same = BlockUtil.arraySame(a, b);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"array1 and array2 cannot be null\")) {\n        same = false; // or rethrow if this indicates a bug\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always null-check and length-check arrays before any identity-comparison helper.","Treat differing lengths as 'not equal' semantics rather than an error in your own wrappers.","Ensure arrays passed to block-comparison utilities come from blocks with the same position count.","Unit-test custom block code with null and mismatched-length arrays."],"tags":["presto","block","argument-validation","null-check"],"backgroundTag":"invalid-argument","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}