Skip to content

Commit dc87e0c

Browse files
dmitrygusevKostyaSha
authored andcommitted
Proposed fix for #830 (#832)
* Proposed fix for #830 * Simplify the fix for #830
1 parent 53ee7e1 commit dc87e0c

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import java.util.concurrent.TimeUnit;
77

8-
import javax.annotation.CheckForNull;
9-
108
import org.slf4j.Logger;
119
import org.slf4j.LoggerFactory;
1210

@@ -23,12 +21,17 @@ public class BuildImageResultCallback extends ResultCallbackTemplate<BuildImageR
2321

2422
private static final Logger LOGGER = LoggerFactory.getLogger(BuildImageResultCallback.class);
2523

26-
@CheckForNull
27-
private BuildResponseItem latestItem = null;
24+
private String imageId;
25+
26+
private String error;
2827

2928
@Override
3029
public void onNext(BuildResponseItem item) {
31-
this.latestItem = item;
30+
if (item.isBuildSuccessIndicated()) {
31+
this.imageId = item.getImageId();
32+
} else if (item.isErrorIndicated()) {
33+
this.error = item.getError();
34+
}
3235
LOGGER.debug(item.toString());
3336
}
3437

@@ -65,13 +68,14 @@ public String awaitImageId(long timeout, TimeUnit timeUnit) {
6568
}
6669

6770
private String getImageId() {
68-
if (latestItem == null) {
71+
if (imageId != null) {
72+
return imageId;
73+
}
74+
75+
if (error == null) {
6976
throw new DockerClientException("Could not build image");
70-
} else if (!latestItem.isBuildSuccessIndicated()) {
71-
throw new DockerClientException("Could not build image: " + latestItem.getError());
72-
} else {
73-
return latestItem.getImageId();
7477
}
75-
}
7678

79+
throw new DockerClientException("Could not build image: " + error);
80+
}
7781
}

0 commit comments

Comments
 (0)