Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8370342

HttpExchange's attributes are the same as HttpContext's attributes

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 26
    • core-libs
    • None
    • behavioral
    • low
    • It is a behavior change, though compatible with other implementations. A system property allows old behavior to be restored.
    • Java API, System or security property
    • JDK

      Summary

      The apidoc and impl for HttpExchange.get/setAttributes is not clear on whether the attribute map is per exchange or per context.

      Problem

      The apidoc and impl for HttpExchange.get/setAttributes is not clear on whether the attribute map is per exchange or per context. Some implementations treat them as per exchange, whereas the default JDK impl treats them as per context. It is more useful to treat them as per exchange since the per context attributes are separately available through HttpContext.getAttributes.

      This is a behavior change though, so it is proposed to add a system property to restore the old behavior.

      Solution

      As outlined above

      Specification

      No API change, but the behavior change is documented in the following addition to the jdk.httpserver module-info

      * @implNote
       * Prior to JDK 26, in the JDK default implementation, the {@link HttpExchange} attribute map was
       * shared with the enclosing {@link HttpContext}.
       * Since JDK 26, by default, exchange attributes are per-exchange and the context attributes must
       * be accessed by calling {@link HttpExchange#getHttpContext() getHttpContext()}{@link
       * HttpContext#getAttributes() .getAttributes()}. <br>
       * A new system property, <b>{@systemProperty jdk.httpserver.attributes}</b> (default value: {@code ""})
       * allows to revert this new behavior. Set this property to "context" to restore the pre JDK 26 behavior.

            michaelm Michael McMahon
            webbuggrp Webbug Group
            Daniel Fuchs, Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: