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

Wrong order problem with Set returned by Subject.getXXXCredentials(Class)

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE PROBLEM :
      The order in which the elements of the Set type field of Subject are obtained should be the same as the order in which they were added.
      When XXXCredentials adds elements, the set type is SecureSet, and the bottom layer is LinkedList, which can ensure order.
      But getXXXCredentials(Class) returns ClassSet, the bottom layer is HashSet, the order of elements in the set collection will depend on the hash value of the elements

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
              Subject subject=new Subject();
              subject.getPrivateCredentials().add("alice");
              subject.getPublicCredentials().add("alice 1");

              subject.getPrivateCredentials().add("tom");
              subject.getPublicCredentials().add("tom 1");

              System.out.println(subject.getPrivateCredentials(String.class).iterator().next());
              System.out.println(subject.getPublicCredentials(String.class).iterator().next());

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      alice
      alice 1
      ACTUAL -
      tom
      tom 1

      ---------- BEGIN SOURCE ----------
              Subject subject=new Subject();
              subject.getPrivateCredentials().add("alice");
              subject.getPublicCredentials().add("alice 1");

              subject.getPrivateCredentials().add("tom");
              subject.getPublicCredentials().add("tom 1");

              System.out.println(subject.getPrivateCredentials(String.class).iterator().next());
              System.out.println(subject.getPublicCredentials(String.class).iterator().next());
      ---------- END SOURCE ----------

      Attachments

        Activity

          People

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: