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

(str) Forwarding append methods in String{Buffer,Builder} are inconsist

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Fixed
    • 6
    • 8
    • core-libs
    • b64
    • generic
    • generic
    • Verified

    Description

      I noticed some other
      inconsistencies in those forwarding append methods that
      perhaps should all be of the form:

      append(ARG...) {
         super.append(ARG...);
         return this;
      }

      but this one in StringBuilder doesn't forward.

           /**
            * @throws IndexOutOfBoundsException {@inheritDoc}
            */
           public StringBuilder append(CharSequence s) {
               if (s == null)
                   s = "null";
               if (s instanceof String)
                   return this.append((String)s);
               if (s instanceof StringBuffer)
                   return this.append((StringBuffer)s);
               if (s instanceof StringBuilder)
                   return this.append((StringBuilder)s);
               return this.append(s, 0, s.length());
           }

      Its super variant in AbstractStringBuilder doesn't
      deal with StringBuilders.

           // Documentation in subclasses because of synchro difference
           public AbstractStringBuilder append(CharSequence s) {
               if (s == null)
                   s = "null";
               if (s instanceof String)
                   return this.append((String)s);
               if (s instanceof StringBuffer)
                   return this.append((StringBuffer)s);
               return this.append(s, 0, s.length());
           }

      What happens when you append a StringBuilder to a StringBuffer?

      StringBuilder.java:
           /**
            * @see java.lang.String#valueOf(java.lang.Object)
            * @see #append(java.lang.String)
            */
           public StringBuilder append(Object obj) {
      return append(String.valueOf(obj));
           }


      StringBuffer.java:
           /**
            * @see java.lang.String#valueOf(java.lang.Object)
            * @see #append(java.lang.String)
            */
           public synchronized StringBuffer append(Object obj) {
      super.append(String.valueOf(obj));
               return this;
           }

      ###@###.### 2004-12-09 23:26:40 GMT

      Attachments

        Activity

          People

            jgish Jim Gish
            iris Iris Clark
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: