Avoid NullPointerException when calling ChangeNotes
So far, when calling loadChangeFromDb(), if for any reason the change does not exist in the database and reading from NoteDb is not enabled, a NullPointerException was thrown. As a consequence, some callers, as for example delete-project plugin, are broken. In this case, the plugin is already handling the NoSuchChangeException but not expecting a NullPointerException which leads to a 500 error in the UI and a 'fatal: internal server error' when invoked from ssh. Change-Id: If7930a769ac88fc235537703b03b23b9a60e7a6b
This commit is contained in:
committed by
David Pursehouse
parent
9a28860560
commit
1a09758fd8
@@ -159,22 +159,18 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
checkArgument(project != null, "project is required");
|
||||
Change change = readOneReviewDbChange(db, changeId);
|
||||
|
||||
if (change == null && args.migration.readChanges()) {
|
||||
// Change isn't in ReviewDb, but its primary storage might be in NoteDb.
|
||||
// Prepopulate the change exists with proper noteDbState field.
|
||||
change = newNoteDbOnlyChange(project, changeId);
|
||||
} else {
|
||||
checkNotNull(change, "change %s not found in ReviewDb", changeId);
|
||||
checkArgument(
|
||||
change.getProject().equals(project),
|
||||
"passed project %s when creating ChangeNotes for %s, but actual project is %s",
|
||||
project,
|
||||
changeId,
|
||||
change.getProject());
|
||||
if (change == null) {
|
||||
if (args.migration.readChanges()) {
|
||||
return newNoteDbOnlyChange(project, changeId);
|
||||
}
|
||||
throw new NoSuchChangeException(changeId);
|
||||
}
|
||||
|
||||
// TODO: Throw NoSuchChangeException when the change is not found in the
|
||||
// database
|
||||
checkArgument(
|
||||
change.getProject().equals(project),
|
||||
"passed project %s when creating ChangeNotes for %s, but actual project is %s",
|
||||
project,
|
||||
changeId,
|
||||
change.getProject());
|
||||
return change;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user