Skip to content

Commit aba89e4

Browse files
committed
SHL-189 - Command classes can now be package protected.
SimpleExecutionStrategy now makes sure the method to be invoked is accessible.
1 parent d304f74 commit aba89e4

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/main/java/org/springframework/shell/core/SimpleExecutionStrategy.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2012 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.shell.core;
1717

18+
import java.lang.reflect.Method;
1819
import java.util.logging.Logger;
1920

2021
import org.springframework.shell.event.ParseResult;
@@ -29,6 +30,7 @@
2930
*
3031
* @author Mark Pollack
3132
* @author Costin Leau
33+
* @author Oliver Gierke
3234
*/
3335
public class SimpleExecutionStrategy implements ExecutionStrategy {
3436

@@ -61,7 +63,9 @@ public Object execute(ParseResult parseResult) throws RuntimeException {
6163

6264
private Object invoke(ParseResult parseResult) {
6365
try {
64-
return ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());
66+
Method method = parseResult.getMethod();
67+
ReflectionUtils.makeAccessible(method);
68+
return ReflectionUtils.invokeMethod(method, parseResult.getInstance(), parseResult.getArguments());
6569
} catch (Throwable th) {
6670
logger.severe("Command failed " + th);
6771
return handleThrowable(th);

src/test/java/org/springframework/shell/core/SimpleExecutionStrategyTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
/**
2929
* @author Costin Leau
30+
* @author Oliver Gierke
3031
*/
3132
public class SimpleExecutionStrategyTest {
3233

@@ -57,6 +58,11 @@ public void afterThrowingInvocation(ParseResult invocationContext, Throwable thr
5758
}
5859
}
5960

61+
static class PackageProtectedTarget {
62+
63+
void someMethod() {}
64+
}
65+
6066
private SimpleExecutionStrategy execution = new SimpleExecutionStrategy();
6167

6268
@Test
@@ -83,4 +89,16 @@ public void testRedirectCommandProcessor() throws Exception {
8389
assertSame(given, target.before);
8490
assertSame(redirect, target.after);
8591
}
86-
}
92+
93+
/**
94+
* @see SHL-189
95+
*/
96+
@Test
97+
public void invokesMethodsOnPackageProtectedTypes() {
98+
99+
Method method = ReflectionUtils.findMethod(PackageProtectedTarget.class, "someMethod");
100+
ParseResult result = new ParseResult(method, new PackageProtectedTarget(), new Object[] {});
101+
102+
execution.execute(result);
103+
}
104+
}

0 commit comments

Comments
 (0)