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

RTF Charset ANSI.TXT wrong encoding for 128 (should be Euro)

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      MS Word 2013

      A DESCRIPTION OF THE PROBLEM :
      RTF Charset ANSI.TXT defines 'Ђ' (=1026) at position 128, which results in a wrong encoding when € is used in Swing, while copyiing the char € from MS Word 2013. We expect to define '€' (=8364) for the index 128 in ANSI.TXT, as it is also defined in http://ascii-table.com/ansi-codes.php.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Copying some Text "abcde€@xyz" from MS Word including the character '€'.
      Pasting the copied text into a JTextPane. A blank was inserted instead of '€'. The inserted text is "abcde @xyz".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The JTextPane contains the Text "abcde€@xyz".
      ACTUAL -
      The JTextPane contains the Text "abcde @xyz".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          public static void main(String[] args) {
              fixEuroCharForANSIEncoding();
          }
          private static void fixEuroCharForANSIEncoding() {
              try {
                  final Class<?> rtfReaderClass = Class.forName("javax.swing.text.rtf.RTFReader");
                  final Method getCharacterSetMethod = rtfReaderClass.getDeclaredMethod("getCharacterSet", String.class);
                  getCharacterSetMethod.setAccessible(true);
                  final char[] charSet = (char[]) getCharacterSetMethod.invoke(null, "ansi");
                  assert (charSet[128] == 8364); // 8364 == '€'
              } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException
                      | IllegalArgumentException | InvocationTargetException e) {
                  Logger.getLogger(StyledTextEditorKit.class.getName()).log(Level.SEVERE, e.getMessage(), e);
              }
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
          private static void fixEuroCharForANSIEncoding() {
              try {
                  final Class<?> rtfReaderClass = Class.forName("javax.swing.text.rtf.RTFReader");
                  final Method getCharacterSetMethod = rtfReaderClass.getDeclaredMethod("getCharacterSet", String.class);
                  getCharacterSetMethod.setAccessible(true);
                  final char[] charSet = (char[]) getCharacterSetMethod.invoke(null, "ansi");
                  charSet[128] = 8364; // == '€'
              } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException
                      | IllegalArgumentException | InvocationTargetException e) {
                  Logger.getLogger(StyledTextEditorKit.class.getName()).log(Level.SEVERE, e.getMessage(), e);
              }
          }

            kaddepalli Krishna Addepalli
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: