diff --git a/src/main/java/org/springframework/shell/core/SimpleExecutionStrategy.java b/src/main/java/org/springframework/shell/core/SimpleExecutionStrategy.java index 35f0dd70..979767a0 100644 --- a/src/main/java/org/springframework/shell/core/SimpleExecutionStrategy.java +++ b/src/main/java/org/springframework/shell/core/SimpleExecutionStrategy.java @@ -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); diff --git a/src/test/java/org/springframework/shell/core/SimpleExecutionStrategyTest.java b/src/test/java/org/springframework/shell/core/SimpleExecutionStrategyTest.java index ada58c6a..9b3c0ce0 100644 --- a/src/test/java/org/springframework/shell/core/SimpleExecutionStrategyTest.java +++ b/src/test/java/org/springframework/shell/core/SimpleExecutionStrategyTest.java @@ -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); } -} \ No newline at end of file + + /** + * @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); + } +}