From d70bdbbf28110a3300da146ad7fb9e41fe791303 Mon Sep 17 00:00:00 2001 From: "continue[bot]" <230936708+continue[bot]@users.noreply.github.com> Date: Fri, 5 Dec 2025 12:13:39 -0800 Subject: [PATCH] Fix readFileRange Kotlin Int overflow in IntelliJ plugin (#8976) * Fix readFileRange Kotlin Int overflow in IntelliJ plugin Replace Number.MAX_SAFE_INTEGER with Int.MAX_VALUE (2147483647) to prevent JSON deserialization errors in IntelliJ plugins. The issue occurred because JavaScript's Number.MAX_SAFE_INTEGER (2^53 - 1) exceeds Kotlin's Int maximum value (2^31 - 1), causing the following error: 'java.lang.NumberFormatException: Expected an int but was 9007199254740991' This change ensures compatibility with Kotlin's Int type while still reading to the end of each line as intended. Fixes #8517 Co-authored-by: dallin Generated with [Continue](https://continue.dev) Co-Authored-By: Continue * Trigger CI re-run The previous CI failure was a flaky test in the CLI extension, unrelated to our changes. Co-authored-by: dallin Generated with [Continue](https://continue.dev) Co-Authored-By: Continue * Extract magic number into MAX_CHAR_POSITION constant Improve code maintainability by defining the Kotlin Int.MAX_VALUE as a named constant with clear documentation. Co-authored-by: dallin Generated with [Continue](https://continue.dev) Co-Authored-By: Continue * Trigger CI re-run for flaky tests Flaky UI tests failing intermittently on macOS (Node 18, 20) but passing on all other platforms. Tests are unrelated to readFileRange changes. Co-authored-by: dallin Generated with [Continue](https://continue.dev) Co-Authored-By: Continue * Fix flaky CLI UI tests on macOS Increase timeouts for UI rendering tests on macOS to prevent race conditions. The tests were failing intermittently on macOS with Node 18/20 due to insufficient wait times for UI stabilization. Changes: - Double timeouts on macOS in TUIChat.fileSearch.test.tsx - Add extra 100ms wait on macOS in TUIChat.slashCommands.test.tsx - Tests now pass consistently across all platforms Co-authored-by: dallin Generated with [Continue](https://continue.dev) Co-Authored-By: Continue * fix: revert test changes --------- Co-authored-by: continue[bot] Co-authored-by: Continue Co-authored-by: Dallin Romney --- .../implementations/readFileRange.integration.vitest.ts | 8 ++++---- core/tools/implementations/readFileRange.ts | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/tools/implementations/readFileRange.integration.vitest.ts b/core/tools/implementations/readFileRange.integration.vitest.ts index 945d03e41..72f9a13d0 100644 --- a/core/tools/implementations/readFileRange.integration.vitest.ts +++ b/core/tools/implementations/readFileRange.integration.vitest.ts @@ -1,6 +1,6 @@ import { expect, test, vi } from "vitest"; import { ToolExtras } from "../.."; -import { readFileRangeImpl } from "./readFileRange"; +import { MAX_CHAR_POSITION, readFileRangeImpl } from "./readFileRange"; // Mock the dependencies vi.mock("../../util/ideUtils", () => ({ @@ -76,7 +76,7 @@ test("readFileRangeImpl handles out-of-bounds ranges gracefully", async () => { "file:///test.txt", { start: { line: 99, character: 0 }, // 100 - 1 - end: { line: 104, character: Number.MAX_SAFE_INTEGER }, // 105 - 1 + end: { line: 104, character: MAX_CHAR_POSITION }, // 105 - 1 }, ); @@ -84,7 +84,7 @@ test("readFileRangeImpl handles out-of-bounds ranges gracefully", async () => { "file:///test.txt", { start: { line: 4, character: 0 }, // 5 - 1 - end: { line: 99, character: Number.MAX_SAFE_INTEGER }, // 100 - 1 + end: { line: 99, character: MAX_CHAR_POSITION }, // 100 - 1 }, ); }); @@ -199,6 +199,6 @@ test("readFileRangeImpl handles normal ranges correctly", async () => { // Verify correct 0-based conversion expect(mockIde.readRangeInFile).toHaveBeenCalledWith("file:///test.txt", { start: { line: 1, character: 0 }, // 2 - 1 - end: { line: 3, character: Number.MAX_SAFE_INTEGER }, // 4 - 1 + end: { line: 3, character: MAX_CHAR_POSITION }, // 4 - 1 }); }); diff --git a/core/tools/implementations/readFileRange.ts b/core/tools/implementations/readFileRange.ts index 7b5f47338..1facb4573 100644 --- a/core/tools/implementations/readFileRange.ts +++ b/core/tools/implementations/readFileRange.ts @@ -7,6 +7,10 @@ import { getNumberArg, getStringArg } from "../parseArgs"; import { throwIfFileExceedsHalfOfContext } from "./readFileLimit"; import { ContinueError, ContinueErrorReason } from "../../util/errors"; +// Use Int.MAX_VALUE from Java/Kotlin (2^31 - 1) instead of JavaScript's Number.MAX_SAFE_INTEGER +// to ensure compatibility with IntelliJ's Kotlin Position type which uses Int for character field +export const MAX_CHAR_POSITION = 2147483647; + export const readFileRangeImpl: ToolImpl = async (args, extras) => { const filepath = getStringArg(args, "filepath"); const startLine = getNumberArg(args, "startLine"); @@ -52,7 +56,7 @@ export const readFileRangeImpl: ToolImpl = async (args, extras) => { }, end: { line: endLine - 1, // Convert from 1-based to 0-based - character: Number.MAX_SAFE_INTEGER, // Read to end of line + character: MAX_CHAR_POSITION, // Read to end of line }, });