{"record":{"id":"779ce8ed27dded26","repo":"Blankj/AndroidUtilCode","slug":"error","errorCode":null,"errorMessage":"{} > {}","messagePattern":"\\{\\} > \\{\\}","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java","lineNumber":860,"sourceCode":"                try {\n                    return Long.parseLong(millis) * 1000;\n                } catch (NumberFormatException e) {\n                    return -1;\n                }\n            }\n            return -1;\n        }\n\n        private static byte[] getDataWithoutDueTime(final byte[] data) {\n            if (hasTimeInfo(data)) {\n                return copyOfRange(data, TIME_INFO_LEN, data.length);\n            }\n            return data;\n        }\n\n        private static byte[] copyOfRange(final byte[] original, final int from, final int to) {\n            int newLength = to - from;\n            if (newLength < 0) throw new IllegalArgumentException(from + \" > \" + to);\n            byte[] copy = new byte[newLength];\n            System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));\n            return copy;\n        }\n\n        private static boolean hasTimeInfo(final byte[] data) {\n            return data != null\n                    && data.length >= TIME_INFO_LEN\n                    && data[0] == '_'\n                    && data[1] == '$'\n                    && data[12] == '$'\n                    && data[13] == '_';\n        }\n    }\n}","sourceCodeStart":842,"sourceCodeEnd":875,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java#L842-L875","documentation":"Thrown by CacheDiskUtils$cacheInner.copyOfRange when the 'from' argument exceeds 'to' (i.e., newLength = to - from < 0). This is a defensive guard mirroring java.util.Arrays.copyOfRange semantics, protecting the subsequent array allocation from a negative length. It indicates corrupted or unexpected time-info header parsing in the on-disk cache byte payload.","triggerScenarios":"The cache data's time-info header (the '_$...$_' marker) reports a TIME_INFO_LEN start offset greater than the total data length, so copyOfRange(data, TIME_INFO_LEN, data.length) is called with from > to. Happens during getDataWithoutDueTime when hasTimeInfo returned true for a malformed/truncated entry.","commonSituations":"Disk-cache corruption (partial writes, app killed mid-write); cache format migration between utilcode versions where TIME_INFO_LEN changed; manually editing or truncating cache files; concurrent access to the cache directory without locking.","solutions":["Clear the affected cache entry/directory so the malformed payload is regenerated.","Ensure cache writes are atomic (write to temp then rename) to avoid truncated entries.","Verify the utilcode version matches the version that wrote the cache (TIME_INFO_LEN is version-specific).","Wrap cache reads in a try/catch and treat a malformed entry as a cache miss."],"exampleFix":"// before\nbyte[] payload = cacheDiskUtils.getBytes(key); // from > to on corrupted entry\n\n// after\nbyte[] payload;\ntry {\n    payload = cacheDiskUtils.getBytes(key);\n} catch (IllegalArgumentException ex) {\n    cacheDiskUtils.remove(key); // drop the corrupted entry\n    payload = null;\n}","handlingStrategy":"try-catch","validationCode":"// No caller-side validation fully prevents this (corruption is on disk).\n// Best pre-check: confirm utilcode version matches the cache writer's version\n// and that cache writes are atomic (write-to-temp + rename).","typeGuard":null,"tryCatchPattern":"byte[] payload;\ntry {\n    payload = cacheDiskUtils.getBytes(key);\n} catch (IllegalArgumentException e) {\n    // malformed time-info header -> treat as cache miss\n    cacheDiskUtils.remove(key);\n    payload = null;\n}","preventionTips":["Write cache entries atomically (temp file + rename) to avoid truncated headers.","Clear the cache directory when upgrading utilcode versions that change TIME_INFO_LEN.","Treat any cache read exception as a soft miss, not a fatal error.","Avoid concurrent uncontrolled writes to the same cache directory."],"tags":["cache","disk-cache","corruption","illegal-argument","cachediskutils","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}