Uploaded image for project: 'Commons CLI'
  1. Commons CLI
  2. CLI-8

Line separator as first char for helpformatter (footer) throws exception

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Component/s: CLI-1.x
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: PC

    • Bugzilla Id:
      21215

      Description

      This might apply for more than just the footer. I only tested footer so don't
      know.

      compile and run this example and you will get an exception

      public class CliError
      {
        public static void main(String[] args)
        {
          Options options = new Options();
          HelpFormatter formatter = new HelpFormatter();
          String footer = System.getProperty("line.separator")+"Hello world.";
          formatter.printHelp(80, "foobar", "", options, footer, true);
        }
      }
      

      result is:

      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      	at java.lang.String.charAt(String.java:582)
      	at org.apache.commons.cli.HelpFormatter.rtrim(HelpFormatter.java:505)
      	at org.apache.commons.cli.HelpFormatter.renderWrappedText(HelpFormatter.java:416)
      	at org.apache.commons.cli.HelpFormatter.printWrapped(HelpFormatter.java:324)
      	at org.apache.commons.cli.HelpFormatter.printWrapped(HelpFormatter.java:318)
      	at org.apache.commons.cli.HelpFormatter.printHelp(HelpFormatter.java:212)
      	at org.apache.commons.cli.HelpFormatter.printHelp(HelpFormatter.java:165)
      	at com.nokia.em.bts.swupdateautomate.test.CliError.main(CliError.java:21)
      
      Exception in thread "main" Process terminated with exit code 1
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                kibaltsis@hotmail.com Teemu Kanstrén
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: