Why are com.sun.net.HttpExchange attributes shared between instances?

Julien Royer eldebaran at gmail.com
Wed Dec 11 17:35:59 UTC 2019


Hi,

> On 11 Dec 2019, at 10:48, Michael McMahon <michael.x.mcmahon at oracle.com> wrote:
> Go ahead and file a bug and we can take it from there.
> 
Thank you Michael.

> Bug Report Submission Complete
> Thank you for taking the time to provide us with your details.
> We will review your report and have assigned it an internal review ID : 9063054.
> Thanks
> 
> Michael.
> 
> On 10/12/2019 11:10, Julien Royer wrote:
>> Hi,
>> 
>> I’m having some troubles understanding how com.sun.net.HttpExchange attributes (setAttribute and getAttribute methods) work. Looking at the Javadoc, I understood that these attributes were specific to a given HttpExchange instance:
>> 
>> https://hg.openjdk.java.net/jdk/jdk/file/a4fb32538898/src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java#l219 <https://hg.openjdk.java.net/jdk/jdk/file/a4fb32538898/src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java#l219>
>> Filter modules may store arbitrary objects with HttpExchange instances as an out-of-band communication mechanism.
>> 
>> This was also my intuition since these methods are defined on HttpExchange and HttpContext (similar to javax.servlet.ServletRequest#setAttribute and javax.servlet.ServletContext#setAttribute).
>> 
>> When using them on a project, I realised that my intuition was wrong though. The source code is very explicit:
>> 
>> https://hg.openjdk.java.net/jdk/jdk/file/a4fb32538898/src/jdk.httpserver/share/classes/sun/net/httpserver/ExchangeImpl.java#l366 <https://hg.openjdk.java.net/jdk/jdk/file/a4fb32538898/src/jdk.httpserver/share/classes/sun/net/httpserver/ExchangeImpl.java#l366>
>> if (attributes == null) {
>>   attributes = getHttpContext().getAttributes();
>> }
>> 
>> Is the code wrong or is my understanding of the Javadoc incorrect? If so, shouldn’t it be clarified somehow?
>> 
>> Thank you,
>> Julien
>> 
>> P.S. this question was also asked on stackoverflow: https://stackoverflow.com/questions/59178977/are-com-sun-net-httpserver-httpexchange-attributes-broken <https://stackoverflow.com/questions/59178977/are-com-sun-net-httpserver-httpexchange-attributes-broken>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20191211/ad755879/attachment.htm>


More information about the net-dev mailing list