SHL-189 - Command classes can now be package protected.
SimpleExecutionStrategy now makes sure the method to be invoked is accessible.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2012 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.shell.core;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.shell.event.ParseResult;
|
||||
@@ -29,6 +30,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Costin Leau
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimpleExecutionStrategy implements ExecutionStrategy {
|
||||
|
||||
@@ -61,7 +63,9 @@ public class SimpleExecutionStrategy implements ExecutionStrategy {
|
||||
|
||||
private Object invoke(ParseResult parseResult) {
|
||||
try {
|
||||
return ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());
|
||||
Method method = parseResult.getMethod();
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
return ReflectionUtils.invokeMethod(method, parseResult.getInstance(), parseResult.getArguments());
|
||||
} catch (Throwable th) {
|
||||
logger.severe("Command failed " + th);
|
||||
return handleThrowable(th);
|
||||
|
||||
@@ -27,6 +27,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimpleExecutionStrategyTest {
|
||||
|
||||
@@ -57,6 +58,11 @@ public class SimpleExecutionStrategyTest {
|
||||
}
|
||||
}
|
||||
|
||||
static class PackageProtectedTarget {
|
||||
|
||||
void someMethod() {}
|
||||
}
|
||||
|
||||
private SimpleExecutionStrategy execution = new SimpleExecutionStrategy();
|
||||
|
||||
@Test
|
||||
@@ -83,4 +89,16 @@ public class SimpleExecutionStrategyTest {
|
||||
assertSame(given, target.before);
|
||||
assertSame(redirect, target.after);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SHL-189
|
||||
*/
|
||||
@Test
|
||||
public void invokesMethodsOnPackageProtectedTypes() {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(PackageProtectedTarget.class, "someMethod");
|
||||
ParseResult result = new ParseResult(method, new PackageProtectedTarget(), new Object[] {});
|
||||
|
||||
execution.execute(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user