Skip to content

Commit 74caed5

Browse files
committed
chore(core): do not expect default DockerCmdExecFactory service
Only fail for missing `DockerCmdExecFactory` service if `getDefaultDockerCmdExecFactory` is called. Otherwise `DockerClientBuilder` can't be used without a `DockerCmdExecFactory` service on classpath.
1 parent 41531ee commit 74caed5

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/main/java/com/github/dockerjava/core/DockerClientBuilder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ public class DockerClientBuilder {
1616
static {
1717
serviceLoader.reload();
1818
Iterator<DockerCmdExecFactory> iterator = serviceLoader.iterator();
19-
if (!iterator.hasNext()) {
20-
throw new RuntimeException("Fatal: Can't find any implementation of '"
21-
+ DockerCmdExecFactory.class.getName() + "' in the current classpath.");
19+
if (iterator.hasNext()) {
20+
factoryClass = iterator.next().getClass();
2221
}
23-
24-
factoryClass = iterator.next().getClass();
2522
}
2623

2724
private DockerClientImpl dockerClient = null;
@@ -49,6 +46,11 @@ public static DockerClientBuilder getInstance(String serverUrl) {
4946
}
5047

5148
public static DockerCmdExecFactory getDefaultDockerCmdExecFactory() {
49+
if (factoryClass == null) {
50+
throw new RuntimeException("Fatal: Can't find any implementation of '"
51+
+ DockerCmdExecFactory.class.getName() + "' in the current classpath.");
52+
}
53+
5254
try {
5355
return factoryClass.newInstance();
5456
} catch (InstantiationException | IllegalAccessException e) {

0 commit comments

Comments
 (0)