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

sun.beans.editors.StringEditor does not correctly encode \n

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b07
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc-fastdebug"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-fastdebug-b93)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-fastdebug-b93-debug, mixed mode)

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

      A DESCRIPTION OF THE PROBLEM :
      sun.beans.editors.StringEditor does not handle the \n character correctly. It should replace it with the string "\\n", but instead passes it through as the carriage return character. This causes strings containing carriage returns to generate incorrect code.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :

      The below class is a good workaround. t must be registered with the PropertyEditorManager so that the bean manager can find it.

      public class StringPropertyEditorSupport extends sun.beans.editors.StringEditor
      {
          
          /** Creates a new instance of StringPropertyEditorSupport */
          public StringPropertyEditorSupport()
          {
          }
          
          public String getJavaInitializationString()
          {
              String value = super.getJavaInitializationString();
              
              value = value.replaceAll("\\n", "\\\\n\" +\n \"");
              
              return value;
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              malenkov Sergey Malenkov (Inactive)
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: