title: WebTarget and thread safety
body: <p>My understanding is that Jersey's WebTargets are thread safe and can be called concurrently but I have a concurrent bug. The code below works fine in one thread but as soon as I call it concurrently I get a NPE.</p>
  
  <pre><code>public static final MultivaluedMap&lt;String, Object&gt; ACCEPT_GZIP =
                  new MultivaluedHashMap&lt;&gt;(hashMap("Accept-Encoding", "gzip"));
  
  webTarget.path("my_web_service/path")
                  .request(MediaType.APPLICATION_JSON_TYPE)
                  .headers(ACCEPT_GZIP)
                  .post(entity(symbols.keySet(), APPLICATION_JSON_TYPE),
                        new GenericType&lt;List&lt;MyPojo&gt;&gt;(){});
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>javax.ws.rs.ProcessingException
  at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
  at org.glassfish.jersey.client.JerseyInvocation$3.call(JerseyInvocation.java:705)
  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:228)
  at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
  at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:701)
  at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:446)
  at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
  at com.assylias.xxx.ws.xx.getLastDates(xx.java:107)
  at com.assylias.xxx.ws.xx.lambda$main$5(xx.java:87)
  at com.assylias.xxx.ws.xx$$Lambda$34/231311211.accept(Unknown Source)
  at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
  at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1359)
  at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
  at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
  at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:902)
  at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1689)
  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1644)
  at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
  
  Caused by: java.lang.NullPointerException
  at java.util.LinkedList$ListItr.next(LinkedList.java:893)
  at jersey.repackaged.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
  at org.glassfish.jersey.filter.LoggingFilter.printPrefixedHeaders(LoggingFilter.java:190)
  at org.glassfish.jersey.filter.LoggingFilter.filter(LoggingFilter.java:230)
  at org.glassfish.jersey.client.ClientFilteringStages$RequestFilteringStage.apply(ClientFilteringStages.java:110)
  at org.glassfish.jersey.client.ClientFilteringStages$RequestFilteringStage.apply(ClientFilteringStages.java:98)
  at org.glassfish.jersey.process.internal.Stages.process(Stages.java:171)
  at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
  ... 21 more
  </code></pre>