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) {