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

Properties#list should warn against non-String values

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • core-libs
    • None
    • minimal
    • Documentation only change to align with long-standing behavior.
    • Java API
    • SE

      Summary

      Specify the ClassCastException thrown by Properties.list(PrintStream) and Properties.list(PrintWriter) when a compromised Properties object contains a non-String value.

      Problem

      Properties#list methods throw ClassCastException when the Properties instance contains a non-String value; this is not specified. Since there already exists wording that warns about failures when a Properties object is compromised with either non-String keys or values, these methods should be properly updated in this regard.

      Solution

      Update the throws tag in the specification for both these methods. Update the existing class description wording about compromised Properties objects. The changes should be minimal since the behavior only occurs when the Properties object is compromised via put/putAll (which is advised against).

      Specification

      In the class description, amend the existing "compromised" wording,

        * {@code Strings}.  The {@code setProperty} method should be used
      - * instead.  If the {@code store} or {@code save} method is called
      + * instead. If the {@code store}, {@code save}, or {@code list} method is called
        * on a "compromised" {@code Properties} object that contains a
        * non-{@code String} key or value, the call will fail. Similarly,
      - * the call to the {@code propertyNames} or {@code list} method
      + * the call to the {@code propertyNames} method
        * will fail if it is called on a "compromised" {@code Properties}
        * object that contains a non-{@code String} key.
        *

      In list(PrintStream),

      -     * @throws  ClassCastException if any key in this property list
      -     *          is not a string.
      +     * @throws  ClassCastException if either a key or a value
      +     *          in this property list is not a string.

      In list(PrintWriter),

      -     * @throws  ClassCastException if any key in this property list
      -     *          is not a string.
      +     * @throws  ClassCastException if either a key or a value
      +     *          in this property list is not a string.

            jlu Justin Lu
            jlu Justin Lu
            Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: