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

Methods for comparing CharSequence, StringBuilder, and StringBuffer

    XMLWordPrintable

Details

    • b04

    Description

      FULL PRODUCT VERSION :
      Linux tigger 3.13.0-63-generic #103-Ubuntu SMP Fri Aug 14 21:42:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


      ADDITIONAL OS VERSION INFORMATION :
      Linux tigger 3.13.0-63-generic #103-Ubuntu SMP Fri Aug 14 21:42:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Synopsis says it. Anything that implements CharSequence should be a Comparable, for example StringBuilder and StringBuffer. It's not the designer's responsibility to dictate how a class should be used. It's the designer's responsibility to provide functionality as general as possible and a CharSequence is Comparable in general.

      REGRESSION. Last worked in version 8u60

      ADDITIONAL REGRESSION INFORMATION:
      True in every release.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create CharSequenceBug.java and compile using the code provided below.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compiling CharSequenceBug.java should compile successfully.
      ACTUAL -
      Compiling CharSequenceBug.java fails to compile.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Resulting compile returns:

      CharSequenceBug.java:8: error: cannot find symbol
              System.err.println(sba.compareTo(sbb));
                                    ^
        symbol: method compareTo(StringBuilder)
        location: variable sba of type StringBuilder
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      public class CharSequenceBug {

          public static void main(String[] args) {
              StringBuilder sba = new StringBuilder().append("a");
              StringBuilder sbb = new StringBuilder().append("b");
              System.err.println(sba.toString().compareTo(sbb.toString()));
              System.err.println(sba.compareTo(sbb));
          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Convert to String. Severity? Simple conversion allows progress, but I need to use the StringBuilder and/or StringBuffer instead.

      Attachments

        Issue Links

          Activity

            People

              joehw Joe Wang
              webbuggrp Webbug Group
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: