Skip to content

Commit d70bdbb

Browse files
continue[bot]ContinueRomneyDa
authored
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 <[email protected]> Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <[email protected]> * Trigger CI re-run The previous CI failure was a flaky test in the CLI extension, unrelated to our changes. Co-authored-by: dallin <[email protected]> Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <[email protected]> * 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 <[email protected]> Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <[email protected]> * 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 <[email protected]> Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <[email protected]> * 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 <[email protected]> Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <[email protected]> * fix: revert test changes --------- Co-authored-by: continue[bot] <continue[bot]@users.noreply.github.com> Co-authored-by: Continue <[email protected]> Co-authored-by: Dallin Romney <[email protected]>
1 parent 05bf720 commit d70bdbb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

core/tools/implementations/readFileRange.integration.vitest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test, vi } from "vitest";
22
import { ToolExtras } from "../..";
3-
import { readFileRangeImpl } from "./readFileRange";
3+
import { MAX_CHAR_POSITION, readFileRangeImpl } from "./readFileRange";
44

55
// Mock the dependencies
66
vi.mock("../../util/ideUtils", () => ({
@@ -76,15 +76,15 @@ test("readFileRangeImpl handles out-of-bounds ranges gracefully", async () => {
7676
"file:///test.txt",
7777
{
7878
start: { line: 99, character: 0 }, // 100 - 1
79-
end: { line: 104, character: Number.MAX_SAFE_INTEGER }, // 105 - 1
79+
end: { line: 104, character: MAX_CHAR_POSITION }, // 105 - 1
8080
},
8181
);
8282

8383
expect(mockIdePartialRange.readRangeInFile).toHaveBeenCalledWith(
8484
"file:///test.txt",
8585
{
8686
start: { line: 4, character: 0 }, // 5 - 1
87-
end: { line: 99, character: Number.MAX_SAFE_INTEGER }, // 100 - 1
87+
end: { line: 99, character: MAX_CHAR_POSITION }, // 100 - 1
8888
},
8989
);
9090
});
@@ -199,6 +199,6 @@ test("readFileRangeImpl handles normal ranges correctly", async () => {
199199
// Verify correct 0-based conversion
200200
expect(mockIde.readRangeInFile).toHaveBeenCalledWith("file:///test.txt", {
201201
start: { line: 1, character: 0 }, // 2 - 1
202-
end: { line: 3, character: Number.MAX_SAFE_INTEGER }, // 4 - 1
202+
end: { line: 3, character: MAX_CHAR_POSITION }, // 4 - 1
203203
});
204204
});

core/tools/implementations/readFileRange.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { getNumberArg, getStringArg } from "../parseArgs";
77
import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
88
import { ContinueError, ContinueErrorReason } from "../../util/errors";
99

10+
// Use Int.MAX_VALUE from Java/Kotlin (2^31 - 1) instead of JavaScript's Number.MAX_SAFE_INTEGER
11+
// to ensure compatibility with IntelliJ's Kotlin Position type which uses Int for character field
12+
export const MAX_CHAR_POSITION = 2147483647;
13+
1014
export const readFileRangeImpl: ToolImpl = async (args, extras) => {
1115
const filepath = getStringArg(args, "filepath");
1216
const startLine = getNumberArg(args, "startLine");
@@ -52,7 +56,7 @@ export const readFileRangeImpl: ToolImpl = async (args, extras) => {
5256
},
5357
end: {
5458
line: endLine - 1, // Convert from 1-based to 0-based
55-
character: Number.MAX_SAFE_INTEGER, // Read to end of line
59+
character: MAX_CHAR_POSITION, // Read to end of line
5660
},
5761
});
5862

0 commit comments

Comments
 (0)