theonedev/onedev · error · NotAcceptableException
'toLineNumber' must not exceed number of lines in the file
Error message
'toLineNumber' must not exceed number of lines in the file
What it means
Range validation in addCodeComment: after reading the file's lines from the head commit, the requested toLineNumber exceeds the actual number of lines in the file, so the annotated span extends past the end of the content. Throws NotAcceptableException. Fix: clamp toLineNumber to the file's line count.
Source
Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:159
throw new NotAcceptableException("'fromLineNumber' must be greater than 0");
if (fromLineNumber > toLineNumber)
throw new NotAcceptableException("'fromLineNumber' must be less than or equal to 'toLineNumber'");
var project = pullRequest.getProject();
var pullRequestService = OneDev.getInstance(PullRequestService.class);
var gitService = OneDev.getInstance(GitService.class);
var codeCommentService = OneDev.getInstance(CodeCommentService.class);
var oldCommitId = ObjectId.fromString(pullRequest.getBaseCommitHash());
var newCommitId = ObjectId.fromString(pullRequest.getLatestUpdate().getHeadCommitHash());
var comparisonBase = pullRequestService.getComparisonBase(pullRequest, oldCommitId, newCommitId);
var newBlobIdent = new BlobIdent(newCommitId.name(), filePath, FileMode.REGULAR_FILE.getBits());
var lines = project.readLines(newBlobIdent, WhitespaceOption.IGNORE_TRAILING, false);
if (lines == null)
throw new NotFoundException("File not found or not a text file in head commit: " + filePath);
if (toLineNumber > lines.size())
throw new NotAcceptableException("'toLineNumber' must not exceed number of lines in the file");
DiffEntryFacade matchingEntry = null;
for (var entry : gitService.diff(project, comparisonBase, newCommitId)) {
if (filePath.equals(entry.getNewPath()) && entry.getChangeType() != ChangeType.DELETE) {
matchingEntry = entry;
break;
}
}
if (matchingEntry == null)
throw new NotAcceptableException("Cannot add code comment outside of diff: '" + filePath + "' is not changed");
var changeType = matchingEntry.getChangeType();
if (changeType == ChangeType.RENAME && matchingEntry.getOldPath().equals(matchingEntry.getNewPath()))
changeType = ChangeType.MODIFY;
var oldDiffBlobIdent = GitUtils.getOldBlobIdent(matchingEntry, comparisonBase.name());
var newDiffBlobIdent = GitUtils.getNewBlobIdent(matchingEntry, newCommitId.name());
var blobChange = new BlobChange(changeType, oldDiffBlobIdent, newDiffBlobIdent, WhitespaceOption.IGNORE_TRAILING) {
View on GitHub (pinned to d44925c47c)
Solutions
- Clamp toLineNumber to the file's line count.
- Re-read the file to get its true length before specifying the range.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:159 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/21d53ec608df63d8.
Report an issue: GitHub.