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

View File

@ -66,6 +66,7 @@ public class CherryPick implements RestModifyView<RevisionResource, CherryPickIn
throw new BadRequestException("destination must be non-empty"); throw new BadRequestException("destination must be non-empty");
} }
@SuppressWarnings("resource")
ReviewDb db = dbProvider.get(); ReviewDb db = dbProvider.get();
if (!control.isVisible(db)) { if (!control.isVisible(db)) {
throw new AuthException("Cherry pick not permitted"); 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); return json.create(ChangeJson.NO_OPTIONS).format(cherryPickedChangeId);
} catch (InvalidChangeOperationException e) { } catch (InvalidChangeOperationException e) {
throw new BadRequestException(e.getMessage()); throw new BadRequestException(e.getMessage());
} catch (MergeException e) { } catch (MergeException | NoSuchChangeException e) {
throw new ResourceConflictException(e.getMessage()); 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(); return change.getDest().get();
} }
@SuppressWarnings("resource")
ReviewDb db = dbProvider.get(); ReviewDb db = dbProvider.get();
PatchSet basePatchSet = parseBase(base); PatchSet basePatchSet = parseBase(base);
if (basePatchSet == null) { if (basePatchSet == null) {

View File

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

View File

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