Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9423

Manage String#stripIndent() conflict with jdk13

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0
    • None

    Description

      It's a preview feature in jdk13 but seems mainstream from jdk14.
      Suggest we add a Boolean variant like we did for GROOVY-6465.
      This doesn't avoid the problem but provides an easy workaround.

      The Java behavior is the same as the Groovy one for many cases but is different in how in treats the last line.
      For Java, the behavior is "The leading white space characters on the last line are also counted even if blank.".

      Here Groovy ignores the last line in calculating the length of incidental whitespace but Java does not.

      String case1 = """
      ..............some text
      """.replace('.', ' ')
      def sij1 = case1.stripIndent()
      def sig1 = case1.stripIndent(true)
      assert sij1 != sig1 // different behavior!
      

      Note: dots are used to indicate incidental whitespace in this example.

      Here Groovy and Java will get the same calculation and yield the same result.

      String case2 = """
      ..............some text
      ..............""".replace('.', ' ')
      def sij2 = case2.stripIndent()
      def sig2 = case2.stripIndent(true)
      assert sij2 == sig2 // same behavior
      

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: