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 9e541d6 No need to nest in else. 9e541d6 is described below commit 9e541d609c23b34249245166d8382597a7ba5e74 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Mar 5 14:47:53 2021 -0500 No need to nest in else. --- src/main/java/org/apache/commons/ognl/ASTAdd.java | 4 +- .../java/org/apache/commons/ognl/ASTBitNegate.java | 5 +- .../java/org/apache/commons/ognl/ASTConst.java | 8 +- src/main/java/org/apache/commons/ognl/ASTCtor.java | 66 +++++------ .../java/org/apache/commons/ognl/ASTMethod.java | 5 +- .../java/org/apache/commons/ognl/ASTNegate.java | 5 +- .../java/org/apache/commons/ognl/ASTProperty.java | 126 +++++++++------------ .../org/apache/commons/ognl/ASTRootVarRef.java | 10 +- .../org/apache/commons/ognl/ASTStaticField.java | 9 +- .../apache/commons/ognl/ArrayPropertyAccessor.java | 20 +--- .../org/apache/commons/ognl/BooleanExpression.java | 2 +- .../apache/commons/ognl/MapPropertyAccessor.java | 6 +- src/main/java/org/apache/commons/ognl/OgnlOps.java | 20 ++-- .../java/org/apache/commons/ognl/OgnlRuntime.java | 78 +++++-------- .../commons/ognl/enhance/ExpressionCompiler.java | 10 +- .../commons/ognl/internal/ClassCacheHandler.java | 34 +++--- .../entry/DeclaredMethodCacheEntryFactory.java | 14 +-- .../entry/MethodAccessCacheEntryFactory.java | 17 +-- .../org/apache/commons/ognl/test/OgnlTestCase.java | 8 +- .../org/apache/commons/ognl/test/Performance.java | 12 +- 20 files changed, 181 insertions(+), 278 deletions(-) diff --git a/src/main/java/org/apache/commons/ognl/ASTAdd.java b/src/main/java/org/apache/commons/ognl/ASTAdd.java index bcf6c9e..89885e9 100644 --- a/src/main/java/org/apache/commons/ognl/ASTAdd.java +++ b/src/main/java/org/apache/commons/ognl/ASTAdd.java @@ -98,11 +98,11 @@ class ASTAdd { return false; } - else if ( parent == null && String.class.isAssignableFrom( lastType.getGetterClass() ) ) + if ( parent == null && String.class.isAssignableFrom( lastType.getGetterClass() ) ) { return true; } - else if ( parent == null && String.class.isAssignableFrom( type.getGetterClass() ) ) + if ( parent == null && String.class.isAssignableFrom( type.getGetterClass() ) ) { return false; } diff --git a/src/main/java/org/apache/commons/ognl/ASTBitNegate.java b/src/main/java/org/apache/commons/ognl/ASTBitNegate.java index ac91826..316fd92 100644 --- a/src/main/java/org/apache/commons/ognl/ASTBitNegate.java +++ b/src/main/java/org/apache/commons/ognl/ASTBitNegate.java @@ -49,10 +49,7 @@ class ASTBitNegate { return "~(" + super.coerceToNumeric( source, context, children[0] ) + ")"; } - else - { - return "~(" + source + ")"; - } + return "~(" + source + ")"; } public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data ) diff --git a/src/main/java/org/apache/commons/ognl/ASTConst.java b/src/main/java/org/apache/commons/ognl/ASTConst.java index 45b0857..8139863 100644 --- a/src/main/java/org/apache/commons/ognl/ASTConst.java +++ b/src/main/java/org/apache/commons/ognl/ASTConst.java @@ -86,7 +86,7 @@ public class ASTConst context.setCurrentType( null ); return "null"; } - else if ( value == null ) + if ( value == null ) { context.setCurrentType( null ); return ""; @@ -101,14 +101,14 @@ public class ASTConst return value.toString(); } - else if ( value != null && Number.class.isAssignableFrom( value.getClass() ) ) + if ( value != null && Number.class.isAssignableFrom( value.getClass() ) ) { context.setCurrentType( OgnlRuntime.getPrimitiveWrapperClass( value.getClass() ) ); context.setCurrentObject( value ); return value.toString(); } - else if ( !( parent != null + if ( !( parent != null && value != null && NumericExpression.class.isAssignableFrom( parent.getClass() ) ) && String.class.isAssignableFrom( value.getClass() ) ) @@ -121,7 +121,7 @@ public class ASTConst return retval.toString(); } - else if ( Character.class.isInstance( value ) ) + if ( Character.class.isInstance( value ) ) { Character val = (Character) value; diff --git a/src/main/java/org/apache/commons/ognl/ASTCtor.java b/src/main/java/org/apache/commons/ognl/ASTCtor.java index 17bfe4b..b3d33cc 100644 --- a/src/main/java/org/apache/commons/ognl/ASTCtor.java +++ b/src/main/java/org/apache/commons/ognl/ASTCtor.java @@ -87,52 +87,48 @@ public class ASTCtor } if ( isArray ) { - if ( args.length == 1 ) + if ( args.length != 1 ) { + throw new OgnlException( "only expect array size or fixed initializer list" ); + } + try { - try + Class componentClass = OgnlRuntime.classForName( context, className ); + List sourceList = null; + int size; + + if ( args[0] instanceof List ) + { + sourceList = (List) args[0]; + size = sourceList.size(); + } + else { - Class componentClass = OgnlRuntime.classForName( context, className ); - List sourceList = null; - int size; + size = (int) OgnlOps.longValue( args[0] ); + } + result = Array.newInstance( componentClass, size ); + if ( sourceList != null ) + { + TypeConverter converter = context.getTypeConverter(); - if ( args[0] instanceof List ) - { - sourceList = (List) args[0]; - size = sourceList.size(); - } - else - { - size = (int) OgnlOps.longValue( args[0] ); - } - result = Array.newInstance( componentClass, size ); - if ( sourceList != null ) + for ( int i = 0, icount = sourceList.size(); i < icount; i++ ) { - TypeConverter converter = context.getTypeConverter(); + Object o = sourceList.get( i ); - for ( int i = 0, icount = sourceList.size(); i < icount; i++ ) + if ( ( o == null ) || componentClass.isInstance( o ) ) { - Object o = sourceList.get( i ); - - if ( ( o == null ) || componentClass.isInstance( o ) ) - { - Array.set( result, i, o ); - } - else - { - Array.set( result, i, - converter.convertValue( context, null, null, null, o, componentClass ) ); - } + Array.set( result, i, o ); + } + else + { + Array.set( result, i, + converter.convertValue( context, null, null, null, o, componentClass ) ); } } } - catch ( ClassNotFoundException ex ) - { - throw new OgnlException( "array component class '" + className + "' not found", ex ); - } } - else + catch ( ClassNotFoundException ex ) { - throw new OgnlException( "only expect array size or fixed initializer list" ); + throw new OgnlException( "array component class '" + className + "' not found", ex ); } } else diff --git a/src/main/java/org/apache/commons/ognl/ASTMethod.java b/src/main/java/org/apache/commons/ognl/ASTMethod.java index c213f59..4b369aa 100644 --- a/src/main/java/org/apache/commons/ognl/ASTMethod.java +++ b/src/main/java/org/apache/commons/ognl/ASTMethod.java @@ -169,10 +169,7 @@ public class ASTMethod return ""; } - else - { - getterClass = method.getReturnType(); - } + getterClass = method.getReturnType(); // TODO: This is a hacky workaround until javassist supports varargs method invocations boolean varArgs = method.isVarArgs(); diff --git a/src/main/java/org/apache/commons/ognl/ASTNegate.java b/src/main/java/org/apache/commons/ognl/ASTNegate.java index 71161a2..dd6f2fe 100644 --- a/src/main/java/org/apache/commons/ognl/ASTNegate.java +++ b/src/main/java/org/apache/commons/ognl/ASTNegate.java @@ -49,10 +49,7 @@ class ASTNegate { return "-" + source; } - else - { - return "-(" + source + ")"; - } + return "-(" + source + ")"; } public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data ) diff --git a/src/main/java/org/apache/commons/ognl/ASTProperty.java b/src/main/java/org/apache/commons/ognl/ASTProperty.java index 5243baf..9825d80 100644 --- a/src/main/java/org/apache/commons/ognl/ASTProperty.java +++ b/src/main/java/org/apache/commons/ognl/ASTProperty.java @@ -189,26 +189,23 @@ public class ASTProperty return "." + m.getName() + "(" + srcString + ")"; } - else - { - PropertyAccessor propertyAccessor = OgnlRuntime.getPropertyAccessor( target.getClass() ); - - // System.out.println("child value : " + _children[0].getValue(context, context.getCurrentObject()) - // + " using propaccessor " + p.getClass().getName() - // + " and srcString " + srcString + " on target: " + target); + PropertyAccessor propertyAccessor = OgnlRuntime.getPropertyAccessor( target.getClass() ); - Object currentObject = context.getCurrentObject(); - if ( ASTConst.class.isInstance( child ) && Number.class.isInstance( currentObject ) ) - { - context.setCurrentType( OgnlRuntime.getPrimitiveWrapperClass( currentObject.getClass() ) ); - } - Object indexValue = propertyAccessor.getProperty( context, target, value ); - result = propertyAccessor.getSourceAccessor( context, target, srcString ); - getterClass = context.getCurrentType(); - context.setCurrentObject( indexValue ); + // System.out.println("child value : " + _children[0].getValue(context, context.getCurrentObject()) + // + " using propaccessor " + p.getClass().getName() + // + " and srcString " + srcString + " on target: " + target); - return result; + Object currentObject = context.getCurrentObject(); + if ( ASTConst.class.isInstance( child ) && Number.class.isInstance( currentObject ) ) + { + context.setCurrentType( OgnlRuntime.getPrimitiveWrapperClass( currentObject.getClass() ) ); } + Object indexValue = propertyAccessor.getProperty( context, target, value ); + result = propertyAccessor.getSourceAccessor( context, target, srcString ); + getterClass = context.getCurrentType(); + context.setCurrentObject( indexValue ); + + return result; } String name = ( (ASTConst) child ).getValue().toString(); @@ -236,14 +233,10 @@ public class ASTProperty } else { - if ( pd instanceof ObjectIndexedPropertyDescriptor ) - { - m = ( (ObjectIndexedPropertyDescriptor) pd ).getIndexedReadMethod(); - } - else - { + if ( !(pd instanceof ObjectIndexedPropertyDescriptor) ) { throw new OgnlException( "property '" + name + "' is not an indexed property" ); } + m = ( (ObjectIndexedPropertyDescriptor) pd ).getIndexedReadMethod(); } if ( parent == null ) @@ -383,7 +376,7 @@ public class ASTProperty { return ( (IndexedPropertyDescriptor) pd ).getIndexedWriteMethod(); } - else if ( ObjectIndexedPropertyDescriptor.class.isInstance( pd ) ) + if ( ObjectIndexedPropertyDescriptor.class.isInstance( pd ) ) { return ( (ObjectIndexedPropertyDescriptor) pd ).getIndexedWriteMethod(); } @@ -425,46 +418,7 @@ public class ASTProperty // System.out.println("astproperty setter using indexed value " + value + " and srcString: " + // srcString); - if ( context.get( "_indexedMethod" ) != null ) - { - m = (Method) context.remove( "_indexedMethod" ); - PropertyDescriptor pd = (PropertyDescriptor) context.remove( "_indexedDescriptor" ); - - boolean lastChild = lastChild( context ); - if ( lastChild ) - { - m = getIndexedWriteMethod( pd ); - - if ( m == null ) - { - throw new UnsupportedCompilationException( - "Indexed property has no corresponding write method." ); - } - } - - setterClass = m.getParameterTypes()[0]; - - Object indexedValue = null; - if ( !lastChild ) - { - indexedValue = OgnlRuntime.callMethod( context, target, m.getName(), new Object[]{ value } ); - } - context.setCurrentType( setterClass ); - context.setCurrentAccessor( - OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass( m, m.getDeclaringClass() ) ); - - if ( !lastChild ) - { - context.setCurrentObject( indexedValue ); - return "." + m.getName() + "(" + srcString + ")"; - } - else - { - return "." + m.getName() + "(" + srcString + ", $3)"; - } - } - else - { + if ( context.get( "_indexedMethod" ) == null ) { PropertyAccessor propertyAccessor = OgnlRuntime.getPropertyAccessor( target.getClass() ); Object currentObject = context.getCurrentObject(); @@ -496,6 +450,38 @@ public class ASTProperty */ return result; } + m = (Method) context.remove( "_indexedMethod" ); + PropertyDescriptor pd = (PropertyDescriptor) context.remove( "_indexedDescriptor" ); + + boolean lastChild = lastChild( context ); + if ( lastChild ) + { + m = getIndexedWriteMethod( pd ); + + if ( m == null ) + { + throw new UnsupportedCompilationException( + "Indexed property has no corresponding write method." ); + } + } + + setterClass = m.getParameterTypes()[0]; + + Object indexedValue = null; + if ( !lastChild ) + { + indexedValue = OgnlRuntime.callMethod( context, target, m.getName(), new Object[]{ value } ); + } + context.setCurrentType( setterClass ); + context.setCurrentAccessor( + OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass( m, m.getDeclaringClass() ) ); + + if ( !lastChild ) + { + context.setCurrentObject( indexedValue ); + return "." + m.getName() + "(" + srcString + ")"; + } + return "." + m.getName() + "(" + srcString + ", $3)"; } String name = ( (ASTConst) child ).getValue().toString(); @@ -532,16 +518,12 @@ public class ASTProperty } else { - if ( pd instanceof ObjectIndexedPropertyDescriptor ) - { - ObjectIndexedPropertyDescriptor opd = (ObjectIndexedPropertyDescriptor) pd; - - m = lastChild( context ) ? opd.getIndexedWriteMethod() : opd.getIndexedReadMethod(); - } - else - { + if ( !(pd instanceof ObjectIndexedPropertyDescriptor) ) { throw new OgnlException( "property '" + name + "' is not an indexed property" ); } + ObjectIndexedPropertyDescriptor opd = (ObjectIndexedPropertyDescriptor) pd; + + m = lastChild( context ) ? opd.getIndexedWriteMethod() : opd.getIndexedReadMethod(); } if ( parent == null ) diff --git a/src/main/java/org/apache/commons/ognl/ASTRootVarRef.java b/src/main/java/org/apache/commons/ognl/ASTRootVarRef.java index 7dc07f5..c747749 100644 --- a/src/main/java/org/apache/commons/ognl/ASTRootVarRef.java +++ b/src/main/java/org/apache/commons/ognl/ASTRootVarRef.java @@ -66,10 +66,7 @@ public class ASTRootVarRef { return ""; } - else - { - return ExpressionCompiler.getRootExpression( this, target, context ); - } + return ExpressionCompiler.getRootExpression( this, target, context ); } public String toSetSourceString( OgnlContext context, Object target ) @@ -78,10 +75,7 @@ public class ASTRootVarRef { return ""; } - else - { - return "$3"; - } + return "$3"; } public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data ) diff --git a/src/main/java/org/apache/commons/ognl/ASTStaticField.java b/src/main/java/org/apache/commons/ognl/ASTStaticField.java index 231e904..7357b93 100644 --- a/src/main/java/org/apache/commons/ognl/ASTStaticField.java +++ b/src/main/java/org/apache/commons/ognl/ASTStaticField.java @@ -130,16 +130,13 @@ public class ASTStaticField { return clazz; } - else if ( clazz.isEnum() ) + if ( clazz.isEnum() ) { return clazz; } - else - { - Field field = clazz.getField( fieldName ); + Field field = clazz.getField( fieldName ); - return field.getType(); - } + return field.getType(); } catch ( ClassNotFoundException e ) { diff --git a/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java b/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java index 82ed58e..ca6094f 100644 --- a/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java +++ b/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java @@ -77,16 +77,12 @@ public class ArrayPropertyAccessor } if ( result == null ) { - if ( index instanceof Number ) - { - int i = ( (Number) index ).intValue(); - - result = ( i >= 0 ) ? Array.get( target, i ) : null; - } - else - { + if ( !(index instanceof Number) ) { throw new NoSuchPropertyException( target, index ); } + int i = ( (Number) index ).intValue(); + + result = ( i >= 0 ) ? Array.get( target, i ) : null; } } return result; @@ -130,14 +126,10 @@ public class ArrayPropertyAccessor } else { - if ( name instanceof String ) - { - super.setProperty( context, target, name, value ); - } - else - { + if ( !(name instanceof String) ) { throw new NoSuchPropertyException( target, name ); } + super.setProperty( context, target, name, value ); } } diff --git a/src/main/java/org/apache/commons/ognl/BooleanExpression.java b/src/main/java/org/apache/commons/ognl/BooleanExpression.java index 3288e22..7dd947f 100644 --- a/src/main/java/org/apache/commons/ognl/BooleanExpression.java +++ b/src/main/java/org/apache/commons/ognl/BooleanExpression.java @@ -89,7 +89,7 @@ public abstract class BooleanExpression { return "false"; } - else if ( "(true)".equals( ret ) ) + if ( "(true)".equals( ret ) ) { return "true"; } diff --git a/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java b/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java index af16434..833ab5e 100644 --- a/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java +++ b/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java @@ -127,17 +127,17 @@ public class MapPropertyAccessor context.setCurrentType( int.class ); return ".size()"; } - else if ( "keys".equals( key ) || "keySet".equals( key ) ) + if ( "keys".equals( key ) || "keySet".equals( key ) ) { context.setCurrentType( Set.class ); return ".keySet()"; } - else if ( "values".equals( key ) ) + if ( "values".equals( key ) ) { context.setCurrentType( Collection.class ); return ".values()"; } - else if ( "isEmpty".equals( key ) ) + if ( "isEmpty".equals( key ) ) { context.setCurrentType( boolean.class ); return ".isEmpty()"; diff --git a/src/main/java/org/apache/commons/ognl/OgnlOps.java b/src/main/java/org/apache/commons/ognl/OgnlOps.java index c75ed2f..6254e20 100644 --- a/src/main/java/org/apache/commons/ognl/OgnlOps.java +++ b/src/main/java/org/apache/commons/ognl/OgnlOps.java @@ -873,22 +873,18 @@ public abstract class OgnlOps } return Math.max( DOUBLE, t1 ); } - else if ( t2 >= MIN_REAL_TYPE ) + if ( t2 < MIN_REAL_TYPE ) { + return Math.max( t1, t2 ); + } + if ( t1 < INT ) { - if ( t1 < INT ) - { - return t2; - } - if ( t1 == BIGINT ) - { - return BIGDEC; - } - return Math.max( DOUBLE, t2 ); + return t2; } - else + if ( t1 == BIGINT ) { - return Math.max( t1, t2 ); + return BIGDEC; } + return Math.max( DOUBLE, t2 ); } /** diff --git a/src/main/java/org/apache/commons/ognl/OgnlRuntime.java b/src/main/java/org/apache/commons/ognl/OgnlRuntime.java index e670817..755adea 100644 --- a/src/main/java/org/apache/commons/ognl/OgnlRuntime.java +++ b/src/main/java/org/apache/commons/ognl/OgnlRuntime.java @@ -508,7 +508,7 @@ public class OgnlRuntime { return Boolean.TYPE; } - else if ( clazz.getSuperclass() == Number.class ) + if ( clazz.getSuperclass() == Number.class ) { if ( clazz == Integer.class ) { @@ -629,11 +629,11 @@ public class OgnlRuntime { return true; } - else if ( class1.isAssignableFrom( class2 ) ) + if ( class1.isAssignableFrom( class2 ) ) { return false; } - else if ( class2.isAssignableFrom( class1 ) ) + if ( class2.isAssignableFrom( class1 ) ) { return true; } @@ -1071,20 +1071,16 @@ public class OgnlRuntime } if ( methodValue == null ) { - if ( method != null ) + if ( method == null ) { + throw new NoSuchMethodException( propertyName ); + } + try { - try - { - methodValue = invokeMethod( target, method, NoArguments ); - } - catch ( InvocationTargetException ex ) - { - throw new OgnlException( propertyName, ex.getTargetException() ); - } + methodValue = invokeMethod( target, method, NoArguments ); } - else + catch ( InvocationTargetException ex ) { - throw new NoSuchMethodException( propertyName ); + throw new OgnlException( propertyName, ex.getTargetException() ); } } return methodValue; @@ -1203,16 +1199,12 @@ public class OgnlRuntime { Object state; - if ( !Modifier.isStatic( field.getModifiers() ) ) - { - state = context.getMemberAccess().setup( context, target, field, propertyName ); - result = field.get( target ); - context.getMemberAccess().restore( context, target, field, propertyName, state ); - } - else - { + if ( Modifier.isStatic( field.getModifiers() ) ) { throw new NoSuchFieldException( propertyName ); } + state = context.getMemberAccess().setup( context, target, field, propertyName ); + result = field.get( target ); + context.getMemberAccess().restore( context, target, field, propertyName, state ); } catch ( IllegalAccessException ex ) @@ -1292,20 +1284,17 @@ public class OgnlRuntime { return clazz; } - else if ( clazz.isEnum() ) + if ( clazz.isEnum() ) { return Enum.valueOf( (Class<? extends Enum>) clazz, fieldName ); } - else + Field field = clazz.getField( fieldName ); + if ( !Modifier.isStatic(field.getModifiers()) ) { - Field field = clazz.getField( fieldName ); - if ( !Modifier.isStatic(field.getModifiers()) ) - { - throw new OgnlException( "Field " + fieldName + " of class " + className + " is not static" ); - } - - return field.get( null ); + throw new OgnlException( "Field " + fieldName + " of class " + className + " is not static" ); } + + return field.get( null ); } catch ( ClassNotFoundException e ) { @@ -1658,14 +1647,10 @@ public class OgnlRuntime } else { - if ( propertyDescriptor instanceof ObjectIndexedPropertyDescriptor ) - { - method = ( (ObjectIndexedPropertyDescriptor) propertyDescriptor ).getIndexedReadMethod(); - } - else - { + if ( !(propertyDescriptor instanceof ObjectIndexedPropertyDescriptor) ) { throw new OgnlException( "property '" + name + "' is not an indexed property" ); } + method = ( (ObjectIndexedPropertyDescriptor) propertyDescriptor ).getIndexedReadMethod(); } return callMethod( context, source, method.getName(), args ); @@ -1697,14 +1682,10 @@ public class OgnlRuntime } else { - if ( propertyDescriptor instanceof ObjectIndexedPropertyDescriptor ) - { - method = ( (ObjectIndexedPropertyDescriptor) propertyDescriptor ).getIndexedWriteMethod(); - } - else - { + if ( !(propertyDescriptor instanceof ObjectIndexedPropertyDescriptor) ) { throw new OgnlException( "property '" + name + "' is not an indexed property" ); } + method = ( (ObjectIndexedPropertyDescriptor) propertyDescriptor ).getIndexedWriteMethod(); } callMethod( context, source, method.getName(), args ); @@ -1866,13 +1847,13 @@ public class OgnlRuntime { return methodDescriptor.getMethod(); } - else if ( numParms < 0 ) + if ( numParms < 0 ) { if ( methodName.equals( name ) ) { return methodDescriptor.getMethod(); } - else if ( method == null || ( method.getParameterTypes().length > methodParamLen ) ) + if ( method == null || ( method.getParameterTypes().length > methodParamLen ) ) { method = methodDescriptor.getMethod(); } @@ -1899,7 +1880,8 @@ public class OgnlRuntime if ( numParms > 0 && methodDescriptor.getMethod().getParameterTypes().length == numParms ) { return methodDescriptor.getMethod(); - } else if ( (numParms < 0) && (method == null || ( method.getParameterTypes().length + } + if ( (numParms < 0) && (method == null || ( method.getParameterTypes().length > methodDescriptor.getMethod().getParameterTypes().length )) ) { method = methodDescriptor.getMethod(); @@ -1958,7 +1940,7 @@ public class OgnlRuntime { return method.getMethod(); } - else if ( numParms < 0 ) + if ( numParms < 0 ) { return method.getMethod(); } @@ -1984,7 +1966,7 @@ public class OgnlRuntime { return cmethod; } - else if ( numParms < 0 ) + if ( numParms < 0 ) { return cmethod; } diff --git a/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java b/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java index e74fe11..3eed6a8 100644 --- a/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java +++ b/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java @@ -265,7 +265,7 @@ public class ExpressionCompiler { return intface.getName(); } - else if ( intface.getName().indexOf( "Iterator" ) > 0 ) + if ( intface.getName().indexOf( "Iterator" ) > 0 ) { return intface.getName(); } @@ -428,19 +428,19 @@ public class ExpressionCompiler { return List.class; } - else if ( Iterator.class.isAssignableFrom( anIntf ) ) + if ( Iterator.class.isAssignableFrom( anIntf ) ) { return Iterator.class; } - else if ( Map.class.isAssignableFrom( anIntf ) ) + if ( Map.class.isAssignableFrom( anIntf ) ) { return Map.class; } - else if ( Set.class.isAssignableFrom( anIntf ) ) + if ( Set.class.isAssignableFrom( anIntf ) ) { return Set.class; } - else if ( Collection.class.isAssignableFrom( anIntf ) ) + if ( Collection.class.isAssignableFrom( anIntf ) ) { return Collection.class; } diff --git a/src/main/java/org/apache/commons/ognl/internal/ClassCacheHandler.java b/src/main/java/org/apache/commons/ognl/internal/ClassCacheHandler.java index f3a29c3..bde12ce 100644 --- a/src/main/java/org/apache/commons/ognl/internal/ClassCacheHandler.java +++ b/src/main/java/org/apache/commons/ognl/internal/ClassCacheHandler.java @@ -53,28 +53,24 @@ public class ClassCacheHandler for ( Class<?> clazz = forClass; clazz != null; clazz = clazz.getSuperclass() ) { answer = handlers.get( clazz ); - if ( answer == null ) + if ( answer != null ) { + keyFound = clazz; + break; + } + Class<?>[] interfaces = clazz.getInterfaces(); + for ( Class<?> iface : interfaces ) { - Class<?>[] interfaces = clazz.getInterfaces(); - for ( Class<?> iface : interfaces ) + answer = handlers.get( iface ); + if ( answer == null ) { - answer = handlers.get( iface ); - if ( answer == null ) - { - /* Try super-interfaces */ - answer = getHandler( iface, handlers ); - } - if ( answer != null ) - { - keyFound = iface; - break outer; - } + /* Try super-interfaces */ + answer = getHandler( iface, handlers ); + } + if ( answer != null ) + { + keyFound = iface; + break outer; } - } - else - { - keyFound = clazz; - break; } } } diff --git a/src/main/java/org/apache/commons/ognl/internal/entry/DeclaredMethodCacheEntryFactory.java b/src/main/java/org/apache/commons/ognl/internal/entry/DeclaredMethodCacheEntryFactory.java index 68086c4..989e10b 100644 --- a/src/main/java/org/apache/commons/ognl/internal/entry/DeclaredMethodCacheEntryFactory.java +++ b/src/main/java/org/apache/commons/ognl/internal/entry/DeclaredMethodCacheEntryFactory.java @@ -41,18 +41,12 @@ public class DeclaredMethodCacheEntryFactory { return true; } - else + boolean isStatic = Modifier.isStatic( method.getModifiers() ); + if ( key.type == DeclaredMethodCacheEntry.MethodType.STATIC ) { - boolean isStatic = Modifier.isStatic( method.getModifiers() ); - if ( key.type == DeclaredMethodCacheEntry.MethodType.STATIC ) - { - return isStatic; - } - else - { - return !isStatic; - } + return isStatic; } + return !isStatic; } } diff --git a/src/main/java/org/apache/commons/ognl/internal/entry/MethodAccessCacheEntryFactory.java b/src/main/java/org/apache/commons/ognl/internal/entry/MethodAccessCacheEntryFactory.java index 5155458..181ae8b 100644 --- a/src/main/java/org/apache/commons/ognl/internal/entry/MethodAccessCacheEntryFactory.java +++ b/src/main/java/org/apache/commons/ognl/internal/entry/MethodAccessCacheEntryFactory.java @@ -44,20 +44,13 @@ public class MethodAccessCacheEntryFactory { final boolean notPublic = !Modifier.isPublic( method.getModifiers() ) || !Modifier.isPublic( method.getDeclaringClass().getModifiers() ); - if ( notPublic ) - { - if ( !method.isAccessible() ) - { - return INACCESSIBLE_NON_PUBLIC_METHOD; - } - else - { - return ACCESSIBLE_NON_PUBLIC_METHOD; - } + if ( !notPublic ) { + return PUBLIC_METHOD; } - else + if ( !method.isAccessible() ) { - return PUBLIC_METHOD; + return INACCESSIBLE_NON_PUBLIC_METHOD; } + return ACCESSIBLE_NON_PUBLIC_METHOD; } } diff --git a/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java b/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java index 39fc82d..8a39e4f 100644 --- a/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java +++ b/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java @@ -233,14 +233,10 @@ public abstract class OgnlTestCase ex = (Exception) ex.getCause(); } - if ( testedResult instanceof Class ) - { - Assert.assertTrue( Exception.class.isAssignableFrom( (Class<?>) testedResult ) ); - } - else - { + if ( !(testedResult instanceof Class) ) { throw ex; } + Assert.assertTrue( Exception.class.isAssignableFrom( (Class<?>) testedResult ) ); } } diff --git a/src/test/java/org/apache/commons/ognl/test/Performance.java b/src/test/java/org/apache/commons/ognl/test/Performance.java index 798b676..697cf94 100644 --- a/src/test/java/org/apache/commons/ognl/test/Performance.java +++ b/src/test/java/org/apache/commons/ognl/test/Performance.java @@ -319,17 +319,11 @@ public class Performance { return ( t1 - t0 ) >= MAX_TIME; } - else + if ( ITERATIONS_MODE ) { - if ( ITERATIONS_MODE ) - { - return _iterations >= MAX_ITERATIONS; - } - else - { - throw new RuntimeException( "no maximums specified" ); - } + return _iterations >= MAX_ITERATIONS; } + throw new RuntimeException( "no maximums specified" ); } /*