You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/08/29 17:38:50 UTC
[groovy] 01/01: reduce impact of makeAccessible(AccessibleObject)
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch set-accessible
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 3499c07b88483c472dc5bdc253b60a06c9578544
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Aug 29 12:38:34 2020 -0500
reduce impact of makeAccessible(AccessibleObject)
---
.../java/org/codehaus/groovy/reflection/ReflectionUtils.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
index 780e7a7..411b79d 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
@@ -196,8 +196,14 @@ public class ReflectionUtils {
// to be run in PrivilegedAction!
public static Optional<AccessibleObject> makeAccessible(final AccessibleObject ao) {
- AccessibleObject[] result = makeAccessible(new AccessibleObject[] {ao});
- return Optional.ofNullable(result.length == 0 ? null : result[0]);
+ try {
+ if (ao.isAccessible() || trySetAccessible(ao)) {
+ return Optional.of(ao);
+ }
+ } catch (Throwable ignore) {
+ // swallow for strict security managers, module systems, android, etc.
+ }
+ return Optional.empty();
}
// to be run in PrivilegedAction!