Skip to content

Commit d16af43

Browse files
emacampolophilwebb
authored andcommitted
Replace try with try-with-resources
Update existing try/finally/close blocks to use "try with resources" See gh-9781
1 parent 798fe5e commit d16af43

File tree

2 files changed

+4
-16
lines changed
  • spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client
  • spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools

2 files changed

+4
-16
lines changed

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/TunnelClient.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,9 @@ public void run() {
170170

171171
private void handleConnection(SocketChannel socketChannel) throws Exception {
172172
Closeable closeable = new SocketCloseable(socketChannel);
173-
WritableByteChannel outputChannel = TunnelClient.this.tunnelConnection
174-
.open(socketChannel, closeable);
175173
TunnelClient.this.listeners.fireOpenEvent(socketChannel);
176-
try {
174+
try (WritableByteChannel outputChannel = TunnelClient.this.tunnelConnection
175+
.open(socketChannel, closeable)) {
177176
logger.trace("Accepted connection to tunnel client from "
178177
+ socketChannel.socket().getRemoteSocketAddress());
179178
while (true) {
@@ -189,9 +188,6 @@ private void handleConnection(SocketChannel socketChannel) throws Exception {
189188
}
190189
}
191190
}
192-
finally {
193-
outputChannel.close();
194-
}
195191
}
196192

197193
protected void stopAcceptingConnections() {

spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarWriter.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ public void writeNestedLibrary(String destination, Library library)
186186

187187
private long getNestedLibraryTime(File file) {
188188
try {
189-
JarFile jarFile = new JarFile(file);
190-
try {
189+
try (JarFile jarFile = new JarFile(file)) {
191190
Enumeration<JarEntry> entries = jarFile.entries();
192191
while (entries.hasMoreElements()) {
193192
JarEntry entry = entries.nextElement();
@@ -196,9 +195,6 @@ private long getNestedLibraryTime(File file) {
196195
}
197196
}
198197
}
199-
finally {
200-
jarFile.close();
201-
}
202198
}
203199
catch (Exception ex) {
204200
// Ignore and just use the source file timestamp
@@ -381,13 +377,9 @@ private static class CrcAndSize {
381377
private long size;
382378

383379
CrcAndSize(File file) throws IOException {
384-
FileInputStream inputStream = new FileInputStream(file);
385-
try {
380+
try (FileInputStream inputStream = new FileInputStream(file)) {
386381
load(inputStream);
387382
}
388-
finally {
389-
inputStream.close();
390-
}
391383
}
392384

393385
CrcAndSize(InputStream inputStream) throws IOException {

0 commit comments

Comments
 (0)