Skip to content

DynamicCommand doesn't extend CommandModule #407

Description

@imagejan

The fact that DynamicCommand extends DefaultMutableModule but not CommandModule leads to CommandService.run() returning null, as explained in the [DEBUG] output here:

/**
* A HACK to avoid {@link ClassCastException} when calling run when the
* resultant module will not be a {@link CommandModule}. This is an API design
* flaw in CommandService currently, but for now we work around it rather than
* breaking backwards API compatibility.
*/
private Future<CommandModule> validateFuture(final Future<Module> future,
final CommandInfo info)
{
try {
final Class<?> commandClass = info.loadDelegateClass();
if (Module.class.isAssignableFrom(commandClass)) {
log.debug("The command '" + info.getIdentifier() +
"' extends Module directly. Due to a design flaw in the " +
"CommandService API, the result cannot be coerced to a " +
"Future<CommandModule>, so null will be returned instead. " +
"If you need the resulting module, please instead call " +
"moduleService.run(commandService.getCommand(commandClass), ...).");
return null;

So the workaround is to get the CommandInfo and call ModuleService#run() on it to get the Future<Module>... but is there any chance to make it extend CommandModule but still implement the required interface MutableModule without breaking backwards compatibility?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions