playframework / playframework/play-ws

Exception when adding new value to an existing header through StandaloneAhcWSRequest::addHeader

Open
#204 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:backlog
Dominant language
Scala
Stars
224
Forks
92
Avg merge
1d 19h
Merged PRs (30d)
28

Description

Play Version

2.6.6

API

Java

Operating System

Ubuntu 16.04 LTS
Linux 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

JDK

openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

Library Dependencies

javaWs

Expected Behavior
  1. I'm using StandaloneAhcWSRequest to add a new value for an existing header to a given request. I call the method StandaloneAhcWSRequest::addHeader, line 100 in StandaloneAhcWSRequest.class.
  2. This method calls the method StandaloneAhcWSRequest::addValueTo, line 505.
  3. Then it manages the Map<String, List<String>> headers. If the new header already existed, it takes the list and adds the new value to it. Therefore, if for example we have the header myHeader already existing in headers map with a value1 and we want to add a value2 to that header, in the end it should have: <"myHeader", ["value1", "value2"]>
Actual Behavior
  1. I get UnsupportedOperationException.
  2. The reason is that the implementation used for the list which is going to get the new element added is the scala one. In scala the list is immutable.
Stack trace
...
play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:56)
... 6 common frames omitted
Caused by: java.lang.UnsupportedOperationException: null
at java.util.AbstractList.add(AbstractList.java:148)
at java.util.AbstractList.add(AbstractList.java:108)
at play.libs.ws.ahc.StandaloneAhcWSRequest.addValueTo(StandaloneAhcWSRequest.java:508)
at play.libs.ws.ahc.StandaloneAhcWSRequest.addHeader(StandaloneAhcWSRequest.java:101)
at play.libs.ws.ahc.StandaloneAhcWSRequest.addHeader(StandaloneAhcWSRequest.java:41) 
...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with play.libs.ws.ahc.StandaloneAhcWSRequest.addHeader and addValueTo, identified at lines 101 and 508 in the issue, and inspect how an existing header's values list is updated. Confirm that adding a second value no longer throws UnsupportedOperationException and preserves both header values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, scala
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.