{"record":{"id":"ee5222bafadab318","repo":"theonedev/onedev","slug":"fromlinenumber-must-be-less-than-or-equal-to-to","errorCode":null,"errorMessage":"'fromLineNumber' must be less than or equal to 'toLineNumber'","messagePattern":"'fromLineNumber' must be less than or equal to 'toLineNumber'","errorType":"validation","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java","lineNumber":143,"sourceCode":"\n    public static List<Map<String, Object>> getComments(PullRequest pullRequest) {\n        var comments = new ArrayList<Map<String, Object>>();\n        pullRequest.getComments().stream().sorted(Comparator.comparing(PullRequestComment::getId)).forEach(comment -> {\n            var commentMap = new HashMap<String, Object>();\n            commentMap.put(\"user\", comment.getUser().getName());\n            commentMap.put(\"date\", comment.getDate());\n            commentMap.put(\"content\", comment.getContent());\n            comments.add(commentMap);\n        });\n        return comments;\n    }\n\n    public static CodeComment addCodeComment(PullRequest pullRequest, User user, String filePath,\n            int fromLineNumber, int toLineNumber, String commentContent) {\n        if (fromLineNumber <= 0)\n            throw new NotAcceptableException(\"'fromLineNumber' must be greater than 0\");\n        if (fromLineNumber > toLineNumber)\n            throw new NotAcceptableException(\"'fromLineNumber' must be less than or equal to 'toLineNumber'\");\n\n        var project = pullRequest.getProject();\n        var pullRequestService = OneDev.getInstance(PullRequestService.class);\n        var gitService = OneDev.getInstance(GitService.class);\n        var codeCommentService = OneDev.getInstance(CodeCommentService.class);\n\n        var oldCommitId = ObjectId.fromString(pullRequest.getBaseCommitHash());\n        var newCommitId = ObjectId.fromString(pullRequest.getLatestUpdate().getHeadCommitHash());\n        var comparisonBase = pullRequestService.getComparisonBase(pullRequest, oldCommitId, newCommitId);\n\n        var newBlobIdent = new BlobIdent(newCommitId.name(), filePath, FileMode.REGULAR_FILE.getBits());\n        var lines = project.readLines(newBlobIdent, WhitespaceOption.IGNORE_TRAILING, false);\n        if (lines == null)\n            throw new NotFoundException(\"File not found or not a text file in head commit: \" + filePath);\n        if (toLineNumber > lines.size())\n            throw new NotAcceptableException(\"'toLineNumber' must not exceed number of lines in the file\");\n\n        DiffEntryFacade matchingEntry = null;","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java#L125-L161","documentation":"Input validation guard in addCodeComment: the requested comment range is inverted — fromLineNumber exceeds toLineNumber. Since comments annotate spans of lines (from..to inclusive), a reversed range cannot be mapped to a diff and is rejected with NotAcceptableException. Fix: swap or correct the range so from <= to.","triggerScenarios":"Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:143 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Swap or correct the values so fromLineNumber <= toLineNumber.","Recompute the range from the diff hunk the comment targets."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}