Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1579

NPE can happen in ResteasyProviderFactory.toHeaderString(ResteasyProviderFactory.java:1297)

XMLWordPrintable

    • Hide
      • Add a ClientRequestFilter and add a few headers with null value. e.g.
        @Provider
        public class ApiKeyHeaderFilter implements ClientRequestFilter {
        
            @Override
            public void filter(ClientRequestContext requestContext) throws IOException {
                MultivaluedMap<String, Object> headers = requestContext.getHeaders();
                headers.add("X-Auth-User", null);
            }
        }
        
      • Use resteasy client to call a server
      Show
      Add a ClientRequestFilter and add a few headers with null value. e.g. @Provider public class ApiKeyHeaderFilter implements ClientRequestFilter { @Override public void filter(ClientRequestContext requestContext) throws IOException { MultivaluedMap< String , Object > headers = requestContext.getHeaders(); headers.add( "X-Auth-User" , null ); } } Use resteasy client to call a server

      We use ClientRequestFilter to add extra header value to the request. But didn't check whether the value is null or not. When adding a null value to the header, the REST client will result in

      Caused by: java.lang.NullPointerException
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.toHeaderString(ResteasyProviderFactory.java:1297)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientConfiguration.toHeaderString(ClientConfiguration.java:77)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientRequestHeaders.asMap(ClientRequestHeaders.java:196)
      	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.commitHeaders(ApacheHttpClient4Engine.java:441)
      	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:435)
      	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281)
      	... 9 more
      

              rsigal@redhat.com Ronald Sigal
              pahuang@redhat.com Patrick Huang (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: