JDK-8176072 : READING attributes are not available on TSF
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,9,10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-03-02
  • Updated: 2019-01-02
  • Resolved: 2017-11-24
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 10 JDK 7 JDK 8
10 b34Fixed 7u201Fixed 8u162Fixed
Related Reports
Relates :  
Description
java.text.AttributedCharacterIterator.Attribute.READING doesn't return
correct values from InputMethodEvent when turning TSF (Text Services
Framework) on.  Java depends on IMM32 APIs although not still supported by
Microsoft.

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

import java.text.AttributedCharacterIterator;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import javax.swing.JTextField;
import javax.swing.JFrame;

public class IME {
  public static void main(String ... arg) throws Exception {
    final JTextField t2 = new JTextField();
    t2.setLocation(100, 140);
    t2.setSize(200, 30);
    t2.setEditable(false);

    JTextField t1 = new JTextField();
    t1.setLocation(100, 100);
    t1.setSize(200, 30);
    t1.addInputMethodListener(new InputMethodListener() {
	public void caretPositionChanged(InputMethodEvent event) {}
	public void inputMethodTextChanged(InputMethodEvent event) {
	  AttributedCharacterIterator itr =  event.getText();
	  if (itr != null) {
	    int toCopy = event.getCommittedCharacterCount();
	    itr.first();
	    StringBuilder yomi = new StringBuilder(t2.getText());
	    while (toCopy-- > 0) {
	      if (itr.getIndex() == itr.getRunStart(AttributedCharacterIterator.Attribute.READING)) {
		java.text.Annotation obj = (java.text.Annotation)itr.getAttribute(AttributedCharacterIterator.Attribute.READING);
		yomi.append(obj.getValue());
	      }
	      itr.next();
	    }
	    t2.setText(yomi.toString());
	  }
	}
      });

    JFrame fr = new JFrame();
    fr.setSize(700, 500);
    fr.setLayout(null);
    fr.add(t1);
    fr.add(t2);
    fr.setVisible(true);

  }
}

---------------------ENDSOURCE---------------------------------------------------------

Expected behavior.
Steps to run:
(0) Use IME which supports IMM32 such as OFFICE-IME, and make the setting of
using TSF off.
(1) Type 'a', 'b', 'e', and blank and blank at the first text field.
(2) A drop-down box appears and several candidates are listed.
(3) Select the third one by using down arrow key.
    Be careful not to use enter key here.
(4) Type 's', 'i', 'n', 'z', 'o', 'u'.
    At this point, the yomigana of "abe" is displayed at the second text
field.
(5) Type blank, and select proper one, and type enter key.
    the yomigana of both "abe" and "sinzou" are displayed.

Actual behavior:
Steps to run:
(0) Use IME which supports TSF such as MS-IME, and make the setting of using
TSF on.
(1) Type 'a', 'b', 'e', and blank and blank at the first text field.
(2) A drop-down box appears and several candidates are listed.
(3) Select the second one by using down arrow key.
    Be careful not to use enter key here.
(4) Type 's', 'i', 'n', 'z', 'o', 'u'.
    At this point, the yomigana of "abe" is NOT displayed at the second text
field.
(5) Type blank, and select proper one, and type enter key.
    Only the yomigana of "sinzou" is displayed. 


Comments
Summarizing the Bug Issue : The bug describes a scenario wherein reading (AttributedCharacterIterator.Attribute.READING) attributes are not obtained from the InputMethodEvent text, only for certain portions of the text. In the test case provided, there is a InputMethodListener added to a JTextFiled, which keeps reading the READING attribute whenever the inputMethodTextChanged gets called. For Japanese IME, when the user enters 'a','b','e','space','space' => Chooses a value from the popup that appears (without pressing 'enter')=> And then starts typing the rest of the characters 's','i','n','z','o','u','space','space' and 'enter', the READING attribute for the first part of the text ('a','b','e','space','space') is never received. However, if we press 'enter', after we choose the value from the popup, the READING attributes are obtained. Root Cause: For the scenario, where the user proceeds with typing the second portion without pressing 'enter', IMM sends WM_IME_COMPOSITION with both GCS_COMPSTR and GCS_RESULTSTR. This scenario is handled in AwtInputTextInfor::GetContextData, where we extract the result string using the GCS_RESULTSTR data and store it in m_pResultTextInfor, member variable inside the main AwtInputTextInfor. In this scenario, along with the result string the READING attributes of the first portion of the string is also stored in m_pResultTextInfor. The main AwtInputTextInfor stores the data represented by GCS_COMPSTR, which in this case doesn't have any READING attibute. When GetClauseInfor is called on the main AwtInputTextInfor, it just checks whether the read clause is present within it. If its not present, it just returns NULL even though the GCS_RESULTSTR data present within m_pResultTextInfor has READING attributes present. In the scenario, where 'enter' is pressed, IMM sends WM_IME_COMPOSITION with only GCS_RESULTSTR immediately after processing the 'enter' key and hence the issue is not seen.
16-11-2017

The bug talks about changing the TSF settings ON/OFF. In Windows XP, you can turn it ON/OFF from the "Text Services And Input Languages" section. However, it looks like accessibility to enable/disable TSF settings is not there from Vista Onwards. But again, we can see a difference in behavior when we choose the text from the IME popup using enter and when we don't press enter and continue typing. In the latter case, the yomigana of the first set of characters ('a''b''e') is not obtained from the reading attributes.
16-11-2017

does it affect 9?
22-06-2017