playframework / playframework/play-ws
Exception when adding new value to an existing header through StandaloneAhcWSRequest::addHeader
Nobody has claimed this yet.
- 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
- I'm using
StandaloneAhcWSRequestto add a new value for an existing header to a given request. I call the methodStandaloneAhcWSRequest::addHeader, line 100 inStandaloneAhcWSRequest.class. - This method calls the method
StandaloneAhcWSRequest::addValueTo, line 505. - 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 headermyHeaderalready existing in headers map with avalue1and we want to add avalue2to that header, in the end it should have:<"myHeader", ["value1", "value2"]>
Actual Behavior
- I get
UnsupportedOperationException. - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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