theonedev/onedev · error · NotAcceptableException
'fromLineNumber' must be less than or equal to 'toLineNumber
Error message
'fromLineNumber' must be less than or equal to 'toLineNumber'
What it means
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.
Source
Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:143
public static List<Map<String, Object>> getComments(PullRequest pullRequest) {
var comments = new ArrayList<Map<String, Object>>();
pullRequest.getComments().stream().sorted(Comparator.comparing(PullRequestComment::getId)).forEach(comment -> {
var commentMap = new HashMap<String, Object>();
commentMap.put("user", comment.getUser().getName());
commentMap.put("date", comment.getDate());
commentMap.put("content", comment.getContent());
comments.add(commentMap);
});
return comments;
}
public static CodeComment addCodeComment(PullRequest pullRequest, User user, String filePath,
int fromLineNumber, int toLineNumber, String commentContent) {
if (fromLineNumber <= 0)
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;View on GitHub (pinned to d44925c47c)
Solutions
- Swap or correct the values so fromLineNumber <= toLineNumber.
- Recompute the range from the diff hunk the comment targets.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:143 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/ee5222bafadab318.
Report an issue: GitHub.