Skip to content

Third parameter (once) cannot be recognized #3

@mjfcolas

Description

@mjfcolas

In main method:

  • If number of parameters > 2, then a print usage is displayed.
    if (args.length != 2) usage();
  • However, if number of parameters == 2, then a null pointer is thrown
    if (args[2].equals("once")) { return; }

Consequences:

  • third parameter ("once") cannot be used
  • An error will always be thrown

Here is a proposed modified main method:

  • When checking if arguments are well formated:

      final String thirdArgumentExpectedValue = "once";
      // parse arguments
      final boolean wrongNumberOfArguments = args.length != 2 && args.length != 3;
      final boolean thirdArgumentInWrongFormat = args.length >= 3 && !thirdArgumentExpectedValue.equals(args[2]);
      if (wrongNumberOfArguments || thirdArgumentInWrongFormat)
      	usage();
    

-When checking presence of "once" third parameter

	if (thirdArgumentExpectedValue.equals(args[2])) {
		return;
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions