Open review DB in try-with-resource where appropriate

Try with resource can't be used for instances that are got
through a provider. Suppress the warning in those cases.

Change-Id: I7670151d8f179238bd3e887cc1597902b6f28a91
This commit is contained in:
David Pursehouse 2015-08-27 12:28:00 +09:00
parent 5e615fcc4f
commit 4b8516b3a0
8 changed files with 11 additions and 16 deletions

View File

@ -116,14 +116,7 @@ public class LocalUsernamesToLowerCase extends SiteProgram {
private class Worker extends Thread {
@Override
public void run() {
final ReviewDb db;
try {
db = database.open();
} catch (OrmException e) {
e.printStackTrace();
return;
}
try {
try (ReviewDb db = database.open()){
for (;;) {
final AccountExternalId extId = next();
if (extId == null) {
@ -134,8 +127,8 @@ public class LocalUsernamesToLowerCase extends SiteProgram {
monitor.update(1);
}
}
} finally {
db.close();
} catch (OrmException e) {
e.printStackTrace();
}
}
}

View File

@ -66,6 +66,7 @@ public class CherryPick implements RestModifyView<RevisionResource, CherryPickIn
throw new BadRequestException("destination must be non-empty");
}
@SuppressWarnings("resource")
ReviewDb db = dbProvider.get();
if (!control.isVisible(db)) {
throw new AuthException("Cherry pick not permitted");
@ -87,10 +88,8 @@ public class CherryPick implements RestModifyView<RevisionResource, CherryPickIn
return json.create(ChangeJson.NO_OPTIONS).format(cherryPickedChangeId);
} catch (InvalidChangeOperationException e) {
throw new BadRequestException(e.getMessage());
} catch (MergeException e) {
} catch (MergeException | NoSuchChangeException e) {
throw new ResourceConflictException(e.getMessage());
} catch (NoSuchChangeException e) {
throw new ResourceNotFoundException(e.getMessage());
}
}

View File

@ -114,6 +114,7 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
return change.getDest().get();
}
@SuppressWarnings("resource")
ReviewDb db = dbProvider.get();
PatchSet basePatchSet = parseBase(base);
if (basePatchSet == null) {

View File

@ -217,6 +217,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
private String problemsForSubmittingChangeset(
ChangeSet cs, IdentifiedUser identifiedUser) {
try {
@SuppressWarnings("resource")
ReviewDb db = dbProvider.get();
for (PatchSet.Id psId : cs.patchIds()) {
ChangeControl changeControl = changeControlFactory

View File

@ -37,6 +37,7 @@ public class RequestScopedReviewDbProvider implements Provider<ReviewDb> {
this.cleanup = cleanup;
}
@SuppressWarnings("resource")
@Override
public ReviewDb get() {
if (db == null) {

@ -1 +1 @@
Subproject commit 679301a1b49245c78ca1bce0b62c9fa9e6b32eea
Subproject commit 264b7a00361f8a880cbad389523bf329f1989480

@ -1 +1 @@
Subproject commit d81e2d6d3edc27c7aceea47518cbb03fb5590f11
Subproject commit b19086265e7cb3c23b9fbf7193fbbd16eadc3bf0

@ -1 +1 @@
Subproject commit 082bf62238d4d815636a329cc1ef4d86b36f982e
Subproject commit 6fb010107a7dfdd6baff2b54e65fb74c933d6654