JDK-7051769 : java.text.Bidi.toString() output is wrong
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-06-06
  • Updated: 2011-08-03
  • Resolved: 2011-08-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b01Fixed
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
EVALUATION Output of toString() will be modified as suggested.
11-07-2011

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(); }
06-06-2011