Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

DefaultDockerClient.listVolumes() throws DockerRequestException #603

Closed
berndwarmuth opened this issue Jan 30, 2017 · 1 comment
Closed

Comments

@berndwarmuth
Copy link

Description

Calling DefaultDockerClient.listVolumes() when there are no (named) volumes created on the docker host, a DockerRequestException gets thrown.

How to reproduce

Given a dockerhost with no named volumes created:

  final DefaultDockerClient dockerClient = DefaultDockerClient.builder().uri( ... ).build();
  final VolumeList volumeList = dockerClient.listVolumes( );

What do you expect

The DefaultDockerClient returns an empty VolumeList.

What happened instead

A DockerRequestException gets thrown.

Software:

  • docker version: 1.12
  • Spotify's docker-client version: 7.0.2

Full backtrace

Exception in thread "main" com.spotify.docker.client.exceptions.DockerRequestException: Request error: GET http://192.168.56.14:2375/volumes: 200
	at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:2103)
	at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:2042)
	at com.spotify.docker.client.DefaultDockerClient.listVolumes(DefaultDockerClient.java:2007)
	at dockerclienttest.Main.main(Main.java:56)
Caused by: javax.ws.rs.client.ResponseProcessingException: com.fasterxml.jackson.databind.JsonMappingException: Instantiation of [simple type, class com.spotify.docker.client.messages.VolumeList] value failed: null
	at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:806)
	at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
	at org.glassfish.jersey.client.JerseyInvocation$5.completed(JerseyInvocation.java:773)
	at org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:198)
	at org.glassfish.jersey.client.ClientRuntime.access$300(ClientRuntime.java:79)
	at org.glassfish.jersey.client.ClientRuntime$2.run(ClientRuntime.java:180)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:340)
	at org.glassfish.jersey.client.ClientRuntime$3.run(ClientRuntime.java:210)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Instantiation of [simple type, class com.spotify.docker.client.messages.VolumeList] value failed: null
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.wrapException(StdValueInstantiator.java:399)
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:231)
	at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:135)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:381)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1100)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:294)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:131)
	at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:1470)
	at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:912)
	at com.fasterxml.jackson.jaxrs.base.ProviderBase.readFrom(ProviderBase.java:811)
	at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:256)
	at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:235)
	at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)
	at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
	at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
	at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:808)
	at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
	at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:803)
	... 17 more
Caused by: java.lang.NullPointerException
	at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:258)
	at com.spotify.docker.client.messages.VolumeList.create(VolumeList.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.fasterxml.jackson.databind.introspect.AnnotatedMethod.call(AnnotatedMethod.java:120)
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:227)
	... 33 more
@johnflavin
Copy link
Contributor

I see the problem. When you ask docker for volumes and there are none, it returns null:

$ curl --unix-socket /var/run/docker.sock http://localhost/volumes
{"Volumes":null,"Warnings":null}

When the code in VolumeList.java got converted to use AutoValue, the value of the "Volumes" key was not checked for null. The "Warnings", on the other hand, are explicitly checked. See this except from VolumeList.java:

@JsonCreator
static VolumeList create(
    @JsonProperty("Volumes") final List<Volume> volumes,
    @JsonProperty("Warnings") final List<String> warnings) {
  final ImmutableList<String> warningsCopy = warnings == null
                                             ? null : ImmutableList.copyOf(warnings);
  return new com.spotify.docker.client.messages.AutoValue_VolumeList(ImmutableList.copyOf(volumes), warningsCopy);
}

To fix this, a null check similar to that for warnings should be done for volumes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants