JDK-6689969 : String is wrongly getting flipped even when using lro character in jdk 1.6
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2008-04-17
  • Updated: 2011-02-16
  • Resolved: 2009-01-16
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
If we use LRO character in the string, the string should not be flipped and
it should appear from left to right as it is. But this behaviour is broken in
1.5 and 1.6 for strings having spaces. In 1.3, if I use LRO character in the
string "‭שמשח    " and set it for JTextArea, it
appears as "‭שמשח    ". The string text used is
"\u202D\u05E9\u05DE\u05E9\u05D7\u0020\u0020\u0020\u0020". But the same string
appears as "    ‭שמשח" in 1.6. Testcase below

import java.awt.ComponentOrientation;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;


public class JTextDemo extends JPanel
{
  public JTextDemo()
  {
    JTextArea text2 = new JTextArea(20, 20);
    String string1 =
"\u202D\u05E9\u05DE\u05E9\u05D7\u0020\u0020\u0020\u0020";
    text2.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    text2.setText(string1);
    add(text2);
  }
 
  public static void main(String args[])
  {
    JFrame fr = new JFrame("JTextDemo");
    fr.getContentPane().add(new JTextDemo());
    fr.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent we)
      {
        System.exit(0);
      }
    });
    fr.pack();
    fr.setVisible(true);
  }
} 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the testcase pasted above in JDK 1.6.0 and observe the string

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The string should appear as "‭שמשח    "
ACTUAL -
But the string appears as "    ‭שמשח"

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.ComponentOrientation;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;


public class JTextDemo extends JPanel
{
  public JTextDemo()
  {
    JTextArea text2 = new JTextArea(20, 20);
    String string1 =
"\u202D\u05E9\u05DE\u05E9\u05D7\u0020\u0020\u0020\u0020";
    text2.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    text2.setText(string1);
    add(text2);
  }
 
  public static void main(String args[])
  {
    JFrame fr = new JFrame("JTextDemo");
    fr.getContentPane().add(new JTextDemo());
    fr.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent we)
      {
        System.exit(0);
      }
    });
    fr.pack();
    fr.setVisible(true);
  }
} 
---------- END SOURCE ----------

Comments
EVALUATION Looks like this is probably not a bug. The change in behaviour is a bug in 1.3 that was fixed in 1.4 The Unicode BiDi algorithm states : http://www.unicode.org/reports/tr9/tr9-19.html#Modifications >3.4 Reordering Resolved Levels .. .. >In combination with the following rule, this means that >trailing whitespace will appear at the visual end of the line >(in the paragraph direction) ..
02-05-2008