From 7dddaf51281536bd843dce23f4a20f29f5ec8a50 Mon Sep 17 00:00:00 2001 From: Yasser Zamani Date: Tue, 24 Dec 2019 10:50:46 +0330 Subject: [PATCH] refactor duplicate code. add log info. --- .../opensymphony/xwork2/inject/ContainerImpl.java | 14 ++++++++------ .../com/opensymphony/xwork2/ognl/OgnlUtil.java | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java b/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java index 1fa6b94b9..7b45097c3 100644 --- a/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java +++ b/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java @@ -155,6 +155,11 @@ class ContainerImpl implements Container { return Modifier.isStatic(member.getModifiers()); } + private static boolean isNotPublic(Member member) { + return !Modifier.isPublic(member.getModifiers()) || + !Modifier.isPublic(member.getDeclaringClass().getModifiers()); + } + static class FieldInjector implements Injector { final Field field; @@ -164,8 +169,7 @@ class ContainerImpl implements Container { public FieldInjector(ContainerImpl container, Field field, String name) throws MissingDependencyException { this.field = field; - if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())) - && !field.isAccessible()) { + if (isNotPublic(field) && !field.isAccessible()) { SecurityManager sm = System.getSecurityManager(); try { if (sm != null) { @@ -257,8 +261,7 @@ class ContainerImpl implements Container { public MethodInjector(ContainerImpl container, Method method, String name) throws MissingDependencyException { this.method = method; - if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) - && !method.isAccessible()) { + if (isNotPublic(method) && !method.isAccessible()) { SecurityManager sm = System.getSecurityManager(); try { if (sm != null) { @@ -308,8 +311,7 @@ class ContainerImpl implements Container { this.implementation = implementation; constructor = findConstructorIn(implementation); - if ((!Modifier.isPublic(constructor.getModifiers()) || !Modifier.isPublic(constructor.getDeclaringClass().getModifiers())) - && !constructor.isAccessible()) { + if (isNotPublic(constructor) && !constructor.isAccessible()) { SecurityManager sm = System.getSecurityManager(); try { if (sm != null) { diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java index 27f8fbbf3..cfcd4bce5 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java @@ -190,16 +190,17 @@ public class OgnlUtil { } /** - * @param maxLength Injects the Struts OGNL maximum expression length. + * @param maxLength Injects the Struts OGNL expression maximum length. */ @Inject(value = StrutsConstants.STRUTS_OGNL_EXPRESSION_MAX_LENGTH, required = false) protected void applyExpressionMaxLength(String maxLength) { try { if (maxLength == null || maxLength.isEmpty()) { - // user is going to disable this functionality Ognl.applyExpressionMaxLength(null); + LOG.info("OGNL Expression Max Length disabled."); } else { Ognl.applyExpressionMaxLength(Integer.parseInt(maxLength)); + LOG.info("OGNL Expression Max Length enabled with {}.", maxLength); } } catch (Exception ex) { LOG.error("Unable to set OGNL Expression Max Length {}.", maxLength); // Help configuration debugging.