@Override
  public int run(String[] argv) {
    // initialize FsShell
    init();
    Tracer tracer = new Tracer.Builder("FsShell").
        conf(TraceUtils.wrapHadoopConf(SHELL_HTRACE_PREFIX, getConf())).
        build();
    int exitCode = -1;
    if (argv.length < 1) {
      printUsage(System.err);
    } else {
      String cmd = argv[0];
      Command instance = null;
      try {
        instance = commandFactory.getInstance(cmd);
        if (instance == null) {
          throw new UnknownCommandException();
        }
        TraceScope scope = tracer.newScope(instance.getCommandName());
        if (scope.getSpan() != null) {
          String args = StringUtils.join(" ", argv);
          if (args.length() > 2048) {
            args = args.substring(0, 2048);
          }
          scope.getSpan().addKVAnnotation("args", args);
        }
        try {
          exitCode = instance.run(Arrays.copyOfRange(argv, 1, argv.length));
        } finally {
          scope.close();
        }
      } catch (IllegalArgumentException e) {
        if (e.getMessage() == null) {
          displayError(cmd, "Null exception message");
          e.printStackTrace(System.err);
        } else {
          displayError(cmd, e.getLocalizedMessage());
        }
        printUsage(System.err);
        if (instance != null) {
          printInstanceUsage(System.err, instance);
        }
      } catch (Exception e) {
        // instance.run catches IOE, so something is REALLY wrong if here
        LOG.debug("Error", e);
        displayError(cmd, "Fatal internal error");
        e.printStackTrace(System.err);
      }
    }
    tracer.close();
    return exitCode;
  }
@Test
  public void testExceptionNullMessage() throws Exception {
    final String cmdName = "-cmdExNullMsg";
    final Command cmd = Mockito.mock(Command.class);
    Mockito.when(cmd.run(Mockito.any())).thenThrow(
        new IllegalArgumentException());
    Mockito.when(cmd.getUsage()).thenReturn(cmdName);

    final CommandFactory cmdFactory = Mockito.mock(CommandFactory.class);
    final String[] names = {cmdName};
    Mockito.when(cmdFactory.getNames()).thenReturn(names);
    Mockito.when(cmdFactory.getInstance(cmdName)).thenReturn(cmd);

    FsShell shell = new FsShell(new Configuration());
    shell.commandFactory = cmdFactory;
    try (GenericTestUtils.SystemErrCapturer capture =
             new GenericTestUtils.SystemErrCapturer()) {
      ToolRunner.run(shell, new String[]{cmdName});
      Assertions.assertThat(capture.getOutput())
          .contains(cmdName + ": Null exception message");
    }
  }