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

(spec) Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec

    XMLWordPrintable

Details

    • b122

    Description

      Specification
      http://docs.oracle.com/javase/8/docs/api/java/util/Properties.html#stringPropertyNames--
      says:

      "The returned set is not backed by the Properties object. Changes to this Properties are not reflected in the set, or vice versa."

      The "vice versa" part assumes that the returned set could be changed. In fact the returned instance throws UnsupportedOperationException for an attempt to add anything. The specification needs to be updated/clarified.

      Please see the following code:

      public class PropNames {
          public static void main(String[] args) {
              new java.util.Properties().stringPropertyNames().add("abc");
          }
      }


      The output will be

      Exception in thread "main" java.lang.UnsupportedOperationException
      at java.util.AbstractCollection.add(AbstractCollection.java:262)
      at java.util.Collections$SynchronizedCollection.add(Collections.java:2035)

      This doesn't look perfectly complying to the assertions from the spec

      The following JCK9 test based on the current spec will fail due to this:
      api/java_util/Properties/autd2.html#StringPropertyNames[changesAreNotReflectedInTheProperties]

      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: