United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7051769 java.text.Bidi.toString() output is wrong
JDK-7051769 : java.text.Bidi.toString() output is wrong

Details
Type:
Bug
Submit Date:
2011-06-06
Status:
Resolved
Updated Date:
2011-08-03
Project Name:
JDK
Resolved Date:
2011-08-03
Component:
core-libs
OS:
generic
Sub-Component:
java.text
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
The text part of java.text.Bidi.toString() output is wrong. The first char and its level are displayed twice.

Other things to be changed:

- StringBuilder should be used instead of StringBuffer.

- avoid string concatenation in append(), such as buf.append("[dir: " + direction).

                                    

Comments
SUGGESTED FIX

--- a/src/share/classes/sun/text/bidi/BidiBase.java
+++ b/src/share/classes/sun/text/bidi/BidiBase.java
@@ -3411,18 +3411,18 @@
      * Display the bidi internal state, used in debugging.
      */
     public String toString() {
-        StringBuffer buf = new StringBuffer(super.toString());
+        StringBuilder buf = new StringBuilder(getClass().getName());
 
-        buf.append("[dir: " + direction);
-        buf.append(" baselevel: " + paraLevel);
-        buf.append(" length: " + length);
+        buf.append("[dir: ").append(direction);
+        buf.append(" baselevel: ").append(paraLevel);
+        buf.append(" length: ").append(length);
         buf.append(" runs: ");
         if (levels == null) {
-            buf.append("null");
+            buf.append("none");
         } else {
             buf.append('[');
             buf.append(levels[0]);
-            for (int i = 0; i < levels.length; i++) {
+            for (int i = 1; i < levels.length; i++) {
                 buf.append(' ');
                 buf.append(levels[i]);
             }
@@ -3430,12 +3430,11 @@
         }
         buf.append(" text: [0x");
         buf.append(Integer.toHexString(text[0]));
-        for (int i = 0; i < text.length; i++) {
+        for (int i = 1; i < text.length; i++) {
             buf.append(" 0x");
             buf.append(Integer.toHexString(text[i]));
         }
-        buf.append(']');
-        buf.append(']');
+        buf.append("]]");
 
         return buf.toString();
     }
                                     
2011-06-06
EVALUATION

Output of toString() will be modified as suggested.
                                     
2011-07-11



Hardware and Software, Engineered to Work Together