You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sentry.apache.org by "Alexander Kolbasov (JIRA)" <ji...@apache.org> on 2016/12/16 23:20:58 UTC

[jira] [Created] (SENTRY-1572) SentryMain() shouldn't dynamically load tool class

Alexander Kolbasov created SENTRY-1572:
------------------------------------------

             Summary: SentryMain() shouldn't dynamically load tool class
                 Key: SENTRY-1572
                 URL: https://issues.apache.org/jira/browse/SENTRY-1572
             Project: Sentry
          Issue Type: Improvement
          Components: Sentry
            Reporter: Alexander Kolbasov


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

{code}
    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());
  }
{code}

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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)