Use try-with-resources statements
- instead of finally blocks - in cases of missing try-finally Change-Id: I94f481a33d8e6a3180c436245d6e95e4d525280c
This commit is contained in:
@@ -265,27 +265,19 @@ public class RulesCache {
|
||||
|
||||
private String read(Project.NameKey project, ObjectId rulesId)
|
||||
throws CompileException {
|
||||
Repository git;
|
||||
try {
|
||||
git = gitMgr.openRepository(project);
|
||||
} catch (RepositoryNotFoundException e) {
|
||||
throw new CompileException("Cannot open repository " + project, e);
|
||||
try (Repository git = gitMgr.openRepository(project)) {
|
||||
try {
|
||||
ObjectLoader ldr = git.open(rulesId, Constants.OBJ_BLOB);
|
||||
byte[] raw = ldr.getCachedBytes(SRC_LIMIT);
|
||||
return RawParseUtils.decode(raw);
|
||||
} catch (LargeObjectException e) {
|
||||
throw new CompileException("rules of " + project + " are too large", e);
|
||||
} catch (RuntimeException | IOException e) {
|
||||
throw new CompileException("Cannot load rules of " + project, e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CompileException("Cannot open repository " + project, e);
|
||||
}
|
||||
try {
|
||||
ObjectLoader ldr = git.open(rulesId, Constants.OBJ_BLOB);
|
||||
byte[] raw = ldr.getCachedBytes(SRC_LIMIT);
|
||||
return RawParseUtils.decode(raw);
|
||||
} catch (LargeObjectException e) {
|
||||
throw new CompileException("rules of " + project + " are too large", e);
|
||||
} catch (RuntimeException e) {
|
||||
throw new CompileException("Cannot load rules of " + project, e);
|
||||
} catch (IOException e) {
|
||||
throw new CompileException("Cannot load rules of " + project, e);
|
||||
} finally {
|
||||
git.close();
|
||||
}
|
||||
}
|
||||
|
||||
private BufferingPrologControl newEmptyMachine(ClassLoader cl) {
|
||||
|
Reference in New Issue
Block a user