This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-ognl.git


The following commit(s) were added to refs/heads/master by this push:
     new b33a4a6  Raise embedded if into parent if.
b33a4a6 is described below

commit b33a4a6ce5ad48964d0e7a7fb9cb013b1062e97d
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Feb 28 12:48:00 2021 -0500

    Raise embedded if into parent if.
---
 .../java/org/apache/commons/ognl/ASTChain.java     | 216 ++++++++++-----------
 .../java/org/apache/commons/ognl/OgnlRuntime.java  |  31 +--
 2 files changed, 114 insertions(+), 133 deletions(-)

diff --git a/src/main/java/org/apache/commons/ognl/ASTChain.java 
b/src/main/java/org/apache/commons/ognl/ASTChain.java
index 23026f9..8ca6e3c 100644
--- a/src/main/java/org/apache/commons/ognl/ASTChain.java
+++ b/src/main/java/org/apache/commons/ognl/ASTChain.java
@@ -75,71 +75,68 @@ public class ASTChain
         {
             boolean handled = false;
 
-            if ( i < ilast )
+            if ( (i < ilast) && (children[i] instanceof ASTProperty) )
             {
-                if ( children[i] instanceof ASTProperty )
+                ASTProperty propertyNode = (ASTProperty) children[i];
+                int indexType = propertyNode.getIndexedPropertyType( context, 
result );
+
+                if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
+                    && ( children[i + 1] instanceof ASTProperty ) )
                 {
-                    ASTProperty propertyNode = (ASTProperty) children[i];
-                    int indexType = propertyNode.getIndexedPropertyType( 
context, result );
+                    ASTProperty indexNode = (ASTProperty) children[i + 1];
 
-                    if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
-                        && ( children[i + 1] instanceof ASTProperty ) )
+                    if ( indexNode.isIndexedAccess() )
                     {
-                        ASTProperty indexNode = (ASTProperty) children[i + 1];
+                        Object index = indexNode.getProperty( context, result 
);
 
-                        if ( indexNode.isIndexedAccess() )
+                        if ( index instanceof DynamicSubscript )
                         {
-                            Object index = indexNode.getProperty( context, 
result );
-
-                            if ( index instanceof DynamicSubscript )
+                            if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT 
)
                             {
-                                if ( indexType == 
OgnlRuntime.INDEXED_PROPERTY_INT )
-                                {
-                                    Object array = propertyNode.getValue( 
context, result );
-                                    int len = Array.getLength( array );
-
-                                    switch ( ( (DynamicSubscript) index 
).getFlag() )
-                                    {
-                                        case DynamicSubscript.ALL:
-                                            result = Array.newInstance( 
array.getClass().getComponentType(), len );
-                                            System.arraycopy( array, 0, 
result, 0, len );
-                                            handled = true;
-                                            i++;
-                                            break;
-                                        case DynamicSubscript.FIRST:
-                                            index = ( len > 0 ) ? 0 : -1;
-                                            break;
-                                        case DynamicSubscript.MID:
-                                            index = ( len > 0 ) ? ( len / 2 ) 
: -1;
-                                            break;
-                                        case DynamicSubscript.LAST:
-                                            index = ( len > 0 ) ? ( len - 1 ) 
: -1;
-                                            break;
-                                        default:
-                                            break;
-                                    }
-                                }
-                                else
+                                Object array = propertyNode.getValue( context, 
result );
+                                int len = Array.getLength( array );
+
+                                switch ( ( (DynamicSubscript) index 
).getFlag() )
                                 {
-                                    if ( indexType == 
OgnlRuntime.INDEXED_PROPERTY_OBJECT )
-                                    {
-                                        throw new OgnlException( 
"DynamicSubscript '" + indexNode
-                                            + "' not allowed for object 
indexed property '" + propertyNode + "'" );
-                                    }
+                                    case DynamicSubscript.ALL:
+                                        result = Array.newInstance( 
array.getClass().getComponentType(), len );
+                                        System.arraycopy( array, 0, result, 0, 
len );
+                                        handled = true;
+                                        i++;
+                                        break;
+                                    case DynamicSubscript.FIRST:
+                                        index = ( len > 0 ) ? 0 : -1;
+                                        break;
+                                    case DynamicSubscript.MID:
+                                        index = ( len > 0 ) ? ( len / 2 ) : -1;
+                                        break;
+                                    case DynamicSubscript.LAST:
+                                        index = ( len > 0 ) ? ( len - 1 ) : -1;
+                                        break;
+                                    default:
+                                        break;
                                 }
                             }
-                            if ( !handled )
+                            else
                             {
-                                result =
-                                    OgnlRuntime.getIndexedProperty(
-                                        context,
-                                        result,
-                                        propertyNode.getProperty( context, 
result ).toString(),
-                                        index );
-                                handled = true;
-                                i++;
+                                if ( indexType == 
OgnlRuntime.INDEXED_PROPERTY_OBJECT )
+                                {
+                                    throw new OgnlException( "DynamicSubscript 
'" + indexNode
+                                        + "' not allowed for object indexed 
property '" + propertyNode + "'" );
+                                }
                             }
                         }
+                        if ( !handled )
+                        {
+                            result =
+                                OgnlRuntime.getIndexedProperty(
+                                    context,
+                                    result,
+                                    propertyNode.getProperty( context, result 
).toString(),
+                                    index );
+                            handled = true;
+                            i++;
+                        }
                     }
                 }
             }
@@ -158,78 +155,75 @@ public class ASTChain
 
         for ( int i = 0, ilast = children.length - 2; i <= ilast; ++i )
         {
-            if ( i <= ilast )
+            if ( (i <= ilast) && (children[i] instanceof ASTProperty) )
             {
-                if ( children[i] instanceof ASTProperty )
+                ASTProperty propertyNode = (ASTProperty) children[i];
+                int indexType = propertyNode.getIndexedPropertyType( context, 
target );
+
+                if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
+                    && ( children[i + 1] instanceof ASTProperty ) )
                 {
-                    ASTProperty propertyNode = (ASTProperty) children[i];
-                    int indexType = propertyNode.getIndexedPropertyType( 
context, target );
+                    ASTProperty indexNode = (ASTProperty) children[i + 1];
 
-                    if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
-                        && ( children[i + 1] instanceof ASTProperty ) )
+                    if ( indexNode.isIndexedAccess() )
                     {
-                        ASTProperty indexNode = (ASTProperty) children[i + 1];
+                        Object index = indexNode.getProperty( context, target 
);
 
-                        if ( indexNode.isIndexedAccess() )
+                        if ( index instanceof DynamicSubscript )
                         {
-                            Object index = indexNode.getProperty( context, 
target );
-
-                            if ( index instanceof DynamicSubscript )
+                            if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT 
)
                             {
-                                if ( indexType == 
OgnlRuntime.INDEXED_PROPERTY_INT )
-                                {
-                                    Object array = propertyNode.getValue( 
context, target );
-                                    int len = Array.getLength( array );
-
-                                    switch ( ( (DynamicSubscript) index 
).getFlag() )
-                                    {
-                                        case DynamicSubscript.ALL:
-                                            System.arraycopy( target, 0, 
value, 0, len );
-                                            handled = true;
-                                            i++;
-                                            break;
-                                        case DynamicSubscript.FIRST:
-                                            index = ( len > 0 ) ? 0 : -1;
-                                            break;
-                                        case DynamicSubscript.MID:
-                                            index = ( len > 0 ) ? ( len / 2 ) 
: -1;
-                                            break;
-                                        case DynamicSubscript.LAST:
-                                            index = ( len > 0 ) ? ( len - 1 ) 
: -1;
-                                            break;
-                                        default:
-                                            break;
-                                    }
-                                }
-                                else
+                                Object array = propertyNode.getValue( context, 
target );
+                                int len = Array.getLength( array );
+
+                                switch ( ( (DynamicSubscript) index 
).getFlag() )
                                 {
-                                    if ( indexType == 
OgnlRuntime.INDEXED_PROPERTY_OBJECT )
-                                    {
-                                        throw new OgnlException( 
"DynamicSubscript '" + indexNode
-                                            + "' not allowed for object 
indexed property '" + propertyNode + "'" );
-                                    }
+                                    case DynamicSubscript.ALL:
+                                        System.arraycopy( target, 0, value, 0, 
len );
+                                        handled = true;
+                                        i++;
+                                        break;
+                                    case DynamicSubscript.FIRST:
+                                        index = ( len > 0 ) ? 0 : -1;
+                                        break;
+                                    case DynamicSubscript.MID:
+                                        index = ( len > 0 ) ? ( len / 2 ) : -1;
+                                        break;
+                                    case DynamicSubscript.LAST:
+                                        index = ( len > 0 ) ? ( len - 1 ) : -1;
+                                        break;
+                                    default:
+                                        break;
                                 }
                             }
-                            if ( !handled && i == ilast )
+                            else
                             {
-                                OgnlRuntime.setIndexedProperty( context, 
target,
-                                                                
propertyNode.getProperty( context, target ).toString(),
-                                                                index, value );
-                                handled = true;
-                                i++;
-                            }
-                            else if ( !handled )
-                            {
-                                target =
-                                    OgnlRuntime.getIndexedProperty(
-                                        context,
-                                        target,
-                                        propertyNode.getProperty( context, 
target ).toString(),
-                                        index );
-                                i++;
-                                continue;
+                                if ( indexType == 
OgnlRuntime.INDEXED_PROPERTY_OBJECT )
+                                {
+                                    throw new OgnlException( "DynamicSubscript 
'" + indexNode
+                                        + "' not allowed for object indexed 
property '" + propertyNode + "'" );
+                                }
                             }
                         }
+                        if ( !handled && i == ilast )
+                        {
+                            OgnlRuntime.setIndexedProperty( context, target,
+                                                            
propertyNode.getProperty( context, target ).toString(),
+                                                            index, value );
+                            handled = true;
+                            i++;
+                        }
+                        else if ( !handled )
+                        {
+                            target =
+                                OgnlRuntime.getIndexedProperty(
+                                    context,
+                                    target,
+                                    propertyNode.getProperty( context, target 
).toString(),
+                                    index );
+                            i++;
+                            continue;
+                        }
                     }
                 }
             }
diff --git a/src/main/java/org/apache/commons/ognl/OgnlRuntime.java 
b/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
index 53fac20..0554887 100644
--- a/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
+++ b/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
@@ -1065,12 +1065,9 @@ public class OgnlRuntime
             method = getReadMethod( targetClass, propertyName, 0 );
         }
 
-        if ( checkAccessAndExistence )
+        if ( checkAccessAndExistence && (( method == null ) || 
!context.getMemberAccess().isAccessible( context, target, method, propertyName 
)) )
         {
-            if ( ( method == null ) || 
!context.getMemberAccess().isAccessible( context, target, method, propertyName 
) )
-            {
-                methodValue = NotFound;
-            }
+            methodValue = NotFound;
         }
         if ( methodValue == null )
         {
@@ -1106,12 +1103,9 @@ public class OgnlRuntime
         boolean result = true;
         Method method = getSetMethod( context, ( target == null ) ? null : 
target.getClass(), propertyName );
 
-        if ( checkAccessAndExistence )
+        if ( checkAccessAndExistence && (( method == null ) || 
!context.getMemberAccess().isAccessible( context, target, method, propertyName 
)) )
         {
-            if ( ( method == null ) || 
!context.getMemberAccess().isAccessible( context, target, method, propertyName 
) )
-            {
-                result = false;
-            }
+            result = false;
         }
 
         if ( result )
@@ -1195,12 +1189,9 @@ public class OgnlRuntime
         Class<?> targetClass = target == null ? null : target.getClass();
         Field field = getField( targetClass, propertyName );
 
-        if ( checkAccessAndExistence )
+        if ( checkAccessAndExistence && (( field == null ) || 
!context.getMemberAccess().isAccessible( context, target, field, propertyName 
)) )
         {
-            if ( ( field == null ) || !context.getMemberAccess().isAccessible( 
context, target, field, propertyName ) )
-            {
-                result = NotFound;
-            }
+            result = NotFound;
         }
         if ( result == null )
         {
@@ -1908,14 +1899,10 @@ public class OgnlRuntime
                     if ( numParms > 0 && 
methodDescriptor.getMethod().getParameterTypes().length == numParms )
                     {
                         return methodDescriptor.getMethod();
-                    }
-                    else if ( numParms < 0 )
+                    } else if ( (numParms < 0) && (method == null || ( 
method.getParameterTypes().length
+                        > 
methodDescriptor.getMethod().getParameterTypes().length )) )
                     {
-                        if ( method == null || ( 
method.getParameterTypes().length
-                            > 
methodDescriptor.getMethod().getParameterTypes().length ) )
-                        {
-                            method = methodDescriptor.getMethod();
-                        }
+                        method = methodDescriptor.getMethod();
                     }
                 }
             }

Reply via email to