refactor duplicate code. add log info.

This commit is contained in:
Yasser Zamani
2019-12-24 10:50:46 +03:30
parent 28a7912acd
commit 7dddaf5128
2 changed files with 11 additions and 8 deletions
@@ -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) {
@@ -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.