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

CliBuilder.usage() fails with SIOBE if header/footer longer than 74 chars

    XMLWordPrintableJSON

Details

    Description

      Have a CliBuilder, set a string longer that HelpFormatter.DEFAULT_WIDTH, and try to show usage.

      		CliBuilder cli = new CliBuilder()
      		cli.header = (1..cli.width).collect{'x'}.join()
      		cli.usage()
      		cli.header = (1..cli.width+1).collect{'x'}.join()
      		cli.usage() // SIOBE
      

      Result is:

      usage: groovy
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      
      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 75
      	at java.lang.String.charAt(String.java:658)
      	at org.apache.commons.cli.HelpFormatter.findWrapPos(HelpFormatter.java:904)
      	at org.apache.commons.cli.HelpFormatter.renderWrappedText(HelpFormatter.java:812)
      	at org.apache.commons.cli.HelpFormatter.printWrapped(HelpFormatter.java:694)
      	at org.apache.commons.cli.HelpFormatter.printWrapped(HelpFormatter.java:679)
      	at org.apache.commons.cli.HelpFormatter.printHelp(HelpFormatter.java:486)
      	at org.apache.commons.cli.HelpFormatter.printHelp(HelpFormatter.java:443)
      	at org.apache.commons.cli.HelpFormatter$printHelp.call(Unknown Source)
      	at groovy.util.CliBuilder.usage(CliBuilder.groovy:275)
      	at groovy.util.CliBuilder$usage.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
      	at com.pixeon.medical.pacs.tool.config.TestWithFiles.main(TestWithFiles.groovy:26)
      

      Workaround is to overwrite CliBuilder.width to a large number.

      Attachments

        Activity

          People

            paulk Paul King
            chaves Rafael Chaves
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: