Skip to content

Commit c231b8d

Browse files
author
Marcus Linke
committed
fix issue docker-java#303
1 parent b7787ac commit c231b8d

6 files changed

Lines changed: 20 additions & 25 deletions

File tree

src/main/java/com/github/dockerjava/api/command/DockerCmd.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44

55
public interface DockerCmd<RES_T> extends Closeable {
66

7+
@Override
8+
public void close();
9+
710
}

src/main/java/com/github/dockerjava/core/command/AbstrAsyncDockerCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public <T extends ResultCallback<A_RES_T>> T exec(T resultCallback) {
2525
}
2626

2727
@Override
28-
public void close() throws IOException {
28+
public void close() {
2929
}
3030

3131
}

src/main/java/com/github/dockerjava/core/command/AbstrDockerCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public RES_T exec() throws DockerException {
3434
}
3535

3636
@Override
37-
public void close() throws IOException {
37+
public void close() {
3838
}
3939

4040
protected String registryAuth(AuthConfig authConfig) {

src/main/java/com/github/dockerjava/core/command/BuildImageCmdImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,14 @@ public BuildImageCmd withBuildAuthConfigs(AuthConfigurations authConfigs) {
197197
}
198198

199199
@Override
200-
public void close() throws IOException {
200+
public void close() {
201201
super.close();
202202

203-
tarInputStream.close();
203+
try {
204+
tarInputStream.close();
205+
} catch (IOException e) {
206+
throw new RuntimeException(e);
207+
}
204208
}
205209

206210
@Override

src/main/java/com/github/dockerjava/jaxrs/AbstrAsyncDockerCmdExec.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ public void onError(Throwable throwable) {
5050
@Override
5151
public void onComplete() {
5252
resultCallback.onComplete();
53-
try {
54-
command.close();
55-
} catch (IOException e) {
56-
throw new RuntimeException(e);
57-
}
53+
command.close();
5854
}
5955
};
6056

src/main/java/com/github/dockerjava/jaxrs/AbstrSyncDockerCmdExec.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,17 @@ public AbstrSyncDockerCmdExec(WebTarget baseResource) {
1919
@Override
2020
public RES_T exec(CMD_T command) {
2121
// this hack works because of ResponseStatusExceptionFilter
22-
RES_T result;
23-
try {
24-
result = execute(command);
25-
26-
} catch (ProcessingException e) {
27-
if (e.getCause() instanceof DockerException) {
28-
throw (DockerException) e.getCause();
29-
} else {
30-
throw e;
31-
}
32-
} finally {
22+
try (CMD_T cmd = command) {
3323
try {
34-
command.close();
35-
} catch (IOException e) {
36-
throw new RuntimeException(e);
24+
return execute(cmd);
25+
} catch (ProcessingException e) {
26+
if (e.getCause() instanceof DockerException) {
27+
throw (DockerException) e.getCause();
28+
} else {
29+
throw e;
30+
}
3731
}
3832
}
39-
40-
return result;
4133
}
4234

4335
protected abstract RES_T execute(CMD_T command);

0 commit comments

Comments
 (0)