Skip to content

Commit

Permalink
Identical catch sections in a single try statement. Collapse into a m…
Browse files Browse the repository at this point in the history
…ulti-catch section.
  • Loading branch information
arturobernalg committed Jun 20, 2021
1 parent bc1091e commit 5165bdd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 87 deletions.
20 changes: 2 additions & 18 deletions src/main/java/org/apache/commons/ognl/ASTStaticField.java
Expand Up @@ -92,15 +92,7 @@ else if ( clazz.isEnum() )
result = Modifier.isFinal( field.getModifiers() );
}
}
catch ( ClassNotFoundException e )
{
cause = e;
}
catch ( NoSuchFieldException e )
{
cause = e;
}
catch ( SecurityException e )
catch ( ClassNotFoundException | SecurityException | NoSuchFieldException e )
{
cause = e;
}
Expand Down Expand Up @@ -138,15 +130,7 @@ Class getFieldClass( OgnlContext context )

return field.getType();
}
catch ( ClassNotFoundException e )
{
cause = e;
}
catch ( NoSuchFieldException e )
{
cause = e;
}
catch ( SecurityException e )
catch ( ClassNotFoundException | SecurityException | NoSuchFieldException e )
{
cause = e;
}
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/org/apache/commons/ognl/ObjectPropertyAccessor.java
Expand Up @@ -52,16 +52,10 @@ public Object getPossibleProperty( Map<String, Object> context, Object target, S
{
result = OgnlRuntime.getFieldValue( ognlContext, target, name, true );
}
}
catch ( IntrospectionException ex )
{
throw new OgnlException( name, ex );
}
catch ( OgnlException ex )
} catch ( OgnlException ex )
{
throw ex;
}
catch ( Exception ex )
} catch ( Exception ex )
{
throw new OgnlException( name, ex );
}
Expand Down Expand Up @@ -93,16 +87,10 @@ public Object setPossibleProperty( Map<String, Object> context, Object target, S
result = m.invoke( target, value );
}
}
}
catch ( IntrospectionException ex )
{
throw new OgnlException( name, ex );
}
catch ( OgnlException ex )
} catch ( OgnlException ex )
{
throw ex;
}
catch ( Exception ex )
} catch ( Exception ex )
{
throw new OgnlException( name, ex );
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/apache/commons/ognl/Ognl.java
Expand Up @@ -111,11 +111,7 @@ public static Object parseExpression( String expression )
OgnlParser parser = new OgnlParser( new StringReader( expression ) );
return parser.topLevelExpression();
}
catch ( ParseException e )
{
throw new ExpressionSyntaxException( expression, e );
}
catch ( TokenMgrError e )
catch ( ParseException | TokenMgrError e )
{
throw new ExpressionSyntaxException( expression, e );
}
Expand Down
40 changes: 5 additions & 35 deletions src/main/java/org/apache/commons/ognl/OgnlRuntime.java
Expand Up @@ -927,15 +927,10 @@ public static Object callAppropriateMethod( OgnlContext context, Object source,
return invokeMethod( target, method, convertedArgs );

}
catch ( NoSuchMethodException e )
catch ( NoSuchMethodException | IllegalAccessException e )
{
cause = e;
}
catch ( IllegalAccessException e )
{
cause = e;
}
catch ( InvocationTargetException e )
} catch ( InvocationTargetException e )
{
cause = e.getTargetException();
}
Expand Down Expand Up @@ -1019,26 +1014,13 @@ public static Object callConstructor( OgnlContext context, String className, Obj
}
return ctor.newInstance( actualArgs );
}
catch ( ClassNotFoundException e )
catch ( ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException e )
{
cause = e;
}
catch ( NoSuchMethodException e )
{
cause = e;
}
catch ( IllegalAccessException e )
{
cause = e;
}
catch ( InvocationTargetException e )
} catch ( InvocationTargetException e )
{
cause = e.getTargetException();
}
catch ( InstantiationException e )
{
cause = e;
}

throw new MethodFailedException( className, "new", cause );
}
Expand Down Expand Up @@ -1296,19 +1278,7 @@ public static Object getStaticField( OgnlContext context, String className, Stri

return field.get( null );
}
catch ( ClassNotFoundException e )
{
cause = e;
}
catch ( NoSuchFieldException e )
{
cause = e;
}
catch ( SecurityException e )
{
cause = e;
}
catch ( IllegalAccessException e )
catch ( ClassNotFoundException | IllegalAccessException | SecurityException | NoSuchFieldException e )
{
cause = e;
}
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/org/apache/commons/ognl/SimpleNode.java
Expand Up @@ -243,17 +243,11 @@ public final Object getValue( OgnlContext context, Object source )
{
result = evaluateGetValueBody( context, source );
}
catch ( OgnlException ex )
{
evalException = ex;
throw ex;
}
catch ( RuntimeException ex )
catch ( OgnlException | RuntimeException ex )
{
evalException = ex;
throw ex;
}
finally
} finally
{
Evaluation eval = context.popEvaluation();

Expand Down
Expand Up @@ -67,11 +67,7 @@ public Map<String, PropertyDescriptor> create( Class<?> targetClass )

findObjectIndexedPropertyDescriptors( targetClass, result );
}
catch ( IntrospectionException e )
{
throw new CacheException( e );
}
catch ( OgnlException e )
catch ( IntrospectionException | OgnlException e )
{
throw new CacheException( e );
}
Expand Down

0 comments on commit 5165bdd

Please sign in to comment.