theonedev/onedev · error · NotAcceptableException
Cannot add code comment outside of diff: '${filePath}' is no
Error message
Cannot add code comment outside of diff: '${filePath}' is not changed What it means
Diff-scope check in addCodeComment: the tool only allows comments on lines that are part of the pull request's changes. If the requested filePath is not among the changed files between base and head commits, the comment would have no diff context to attach to, so NotAcceptableException is thrown. Fix: comment only on files modified by the PR.
Source
Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:169
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) {
private static final long serialVersionUID = 1L;
@Override
public Project getProject() {
return project;
}
};
var range = new PlanarRange(fromLineNumber - 1, 0, toLineNumber - 1, lines.get(toLineNumber - 1).length());View on GitHub (pinned to d44925c47c)
Solutions
- Choose a file that is actually changed between the comparison base and head commit.
- Check the PR's changed-file list before selecting the path.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:169 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/1b228c3c58be03e7.
Report an issue: GitHub.