{"record":{"id":"4c26f0f8756099c9","repo":"oracle/graal","slug":"fromindex-fromindex-toindex-toindex","errorCode":null,"errorMessage":"fromIndex(${fromIndex}) > toIndex(${toIndex})","messagePattern":"fromIndex\\((.+?)\\) > toIndex\\((.+?)\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"espresso/src/com.oracle.truffle.espresso.polyglot/src/com/oracle/truffle/espresso/polyglot/collections/AbstractListWithoutField.java","lineNumber":445,"sourceCode":"     * @throws IndexOutOfBoundsException if an endpoint index value is out of range\n     *             {@code (fromIndex < 0 || toIndex > size)}\n     * @throws IllegalArgumentException if the endpoint indices are out of order\n     *             {@code (fromIndex > toIndex)}\n     */\n    public List<E> subList(int fromIndex, int toIndex) {\n        subListRangeCheck(fromIndex, toIndex, size());\n        return (this instanceof RandomAccess ? new RandomAccessSubList<>(this, fromIndex, toIndex) : new SubList<>(this, fromIndex, toIndex));\n    }\n\n    static void subListRangeCheck(int fromIndex, int toIndex, int size) {\n        if (fromIndex < 0) {\n            throw new IndexOutOfBoundsException(\"fromIndex = \" + fromIndex);\n        }\n        if (toIndex > size) {\n            throw new IndexOutOfBoundsException(\"toIndex = \" + toIndex);\n        }\n        if (fromIndex > toIndex) {\n            throw new IllegalArgumentException(\"fromIndex(\" + fromIndex +\n                            \") > toIndex(\" + toIndex + \")\");\n        }\n    }\n\n    // Comparison and hashing\n\n    /**\n     * Compares the specified object with this list for equality. Returns {@code true} if and only\n     * if the specified object is also a list, both lists have the same size, and all corresponding\n     * pairs of elements in the two lists are <i>equal</i>. (Two elements {@code e1} and {@code e2}\n     * are <i>equal</i> if {@code (e1==null ? e2==null :\n     * e1.equals(e2))}.) In other words, two lists are defined to be equal if they contain the same\n     * elements in the same order.\n     *\n     * @implSpec This implementation first checks if the specified object is this list. If so, it\n     *           returns {@code true}; if not, it checks if the specified object is a list. If not,\n     *           it returns {@code false}; if so, it iterates over both lists, comparing\n     *           corresponding pairs of elements. If any comparison returns {@code false}, this","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso/src/com.oracle.truffle.espresso.polyglot/src/com/oracle/truffle/espresso/polyglot/collections/AbstractListWithoutField.java#L427-L463","documentation":"Thrown as IllegalArgumentException by AbstractListWithoutField.subListRangeCheck when fromIndex is greater than toIndex. The interval is ordered: callers must pass start <= end. An inverted range is a logic error distinct from out-of-range indices.","triggerScenarios":"Calling subList(5, 2); computing from = size() - n and to = size() when n > size(); swapping argument order in refactoring; descending ranges expressed as subList(high, low) expecting python-style backwards slices.","commonSituations":"Porting Python slice semantics (list[5:2]) to Java; off-by-one in computed bounds where from overshoots to; copy-paste between subList(x, y) and other APIs with reversed parameter order.","solutions":["Verify fromIndex <= toIndex before the call; swap or reject inverted ranges explicitly.","When computing from a length, clamp: int from = Math.max(0, size - n).","Do not expect negative-index or reversed-slice semantics; normalize ranges first.","Add unit tests covering empty and single-element ranges."],"exampleFix":"// before\nList<E> tail = list.subList(list.size() - n, list.size()); // n > size inverts range\n\n// after\nint from = Math.max(0, list.size() - n);\nList<E> tail = list.subList(from, list.size());","handlingStrategy":"validation","validationCode":"if (fromIndex > toIndex) {\n    throw new IllegalArgumentException(\"fromIndex \" + fromIndex + \" > toIndex \" + toIndex);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not port Python reversed-slice semantics; normalize ranges first.","Assert start <= end in debugging builds for slicing helpers.","Compute from = max(0, size - n) style bounds defensively."],"tags":["collections","illegal-argument","sublist","espresso","polyglot"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}