Uploaded image for project: 'Sentry'
  1. Sentry
  2. SENTRY-1572

SentryMain() shouldn't dynamically load tool class

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1.0
    • Component/s: Sentry
    • Labels:

      Description

      TheSentryMain class currently works by mapping the command name to a Java class that is then dynamically loaded:

          String commandName = commandLine.getOptionValue(COMMAND);
          String commandClazz = COMMANDS.get(commandName);
          Object command;
          try {
            command = Class.forName(commandClazz.trim()).newInstance();
          } catch (Exception e) {
            String msg = "Could not create instance of " + commandClazz + " for command " + commandName;
            throw new IllegalStateException(msg, e);
          }
          if (!(command instanceof Command)) {
            String msg = "Command " + command.getClass().getName() + " is not an instance of "
                + Command.class.getName();
            throw new IllegalStateException(msg);
          }
          ((Command)command).run(commandLine.getArgs());
        }
      

      This ia too complicated and causes subtle problems at runtime. Instead it should just create a new instance of appropriate class and call it directly.

        Attachments

        1. SENTRY-1572.001.patch
          6 kB
          Xinran Tinney
        2. SENTRY-1572.002.patch
          6 kB
          Xinran Tinney
        3. SENTRY-1572.003.patch
          9 kB
          Xinran Tinney
        4. SENTRY-1572.004.patch
          8 kB
          Xinran Tinney
        5. SENTRY-1572.005.patch
          13 kB
          Xinran Tinney

          Activity

            People

            • Assignee:
              xyu2017 Xinran Tinney
              Reporter:
              akolb Alexander Kolbasov
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: