This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push: new be23a22 Align EL implementation with 8.5.x where possible. Cosmetic changes only be23a22 is described below commit be23a22490f8fd7b1c677703f80cc406722689f4 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Jun 11 21:52:16 2019 +0100 Align EL implementation with 8.5.x where possible. Cosmetic changes only Changes include: - re-order methods to reduce diff - re-order catch blocks to reduce diff - document unchecked exceptions in Javadoc rather than method signature - Use varargs for i18n for cleaner code - remove unnecessary (...) - make more use of Util.handleThrowable - whitespace changes --- java/javax/el/ArrayELResolver.java | 43 +++---- java/javax/el/BeanELResolver.java | 44 ++----- java/javax/el/CompositeELResolver.java | 118 ++++++++--------- java/javax/el/ELContext.java | 63 +++++----- java/javax/el/ELException.java | 16 +-- java/javax/el/ELResolver.java | 70 +++++++---- java/javax/el/Expression.java | 4 +- java/javax/el/ExpressionFactory.java | 160 +++++++++++------------- java/javax/el/FunctionMapper.java | 5 - java/javax/el/ListELResolver.java | 28 ++--- java/javax/el/LocalStrings.properties | 14 ++- java/javax/el/LocalStrings_es.properties | 10 +- java/javax/el/MapELResolver.java | 20 ++- java/javax/el/MethodExpression.java | 8 +- java/javax/el/MethodInfo.java | 14 +-- java/javax/el/MethodNotFoundException.java | 25 +--- java/javax/el/PropertyNotFoundException.java | 24 +--- java/javax/el/PropertyNotWritableException.java | 25 +--- java/javax/el/ResourceBundleELResolver.java | 18 +-- java/javax/el/ValueExpression.java | 40 +++--- 20 files changed, 303 insertions(+), 446 deletions(-) diff --git a/java/javax/el/ArrayELResolver.java b/java/javax/el/ArrayELResolver.java index 4204fe4..fa46260 100644 --- a/java/javax/el/ArrayELResolver.java +++ b/java/javax/el/ArrayELResolver.java @@ -34,40 +34,38 @@ public class ArrayELResolver extends ELResolver { } @Override - public Object getValue(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Class<?> getType(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } if (base != null && base.getClass().isArray()) { context.setPropertyResolved(true); - int idx = coerce(property); - if (idx < 0 || idx >= Array.getLength(base)) { - return null; + try { + int idx = coerce(property); + checkBounds(base, idx); + } catch (IllegalArgumentException e) { + // ignore } - return Array.get(base, idx); + return base.getClass().getComponentType(); } return null; } @Override - public Class<?> getType(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Object getValue(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } if (base != null && base.getClass().isArray()) { context.setPropertyResolved(true); - try { - int idx = coerce(property); - checkBounds(base, idx); - } catch (IllegalArgumentException e) { - // ignore + int idx = coerce(property); + if (idx < 0 || idx >= Array.getLength(base)) { + return null; } - return base.getClass().getComponentType(); + return Array.get(base, idx); } return null; @@ -75,9 +73,7 @@ public class ArrayELResolver extends ELResolver { @Override public void setValue(ELContext context, Object base, Object property, - Object value) throws NullPointerException, - PropertyNotFoundException, PropertyNotWritableException, - ELException { + Object value) { if (context == null) { throw new NullPointerException(); } @@ -87,8 +83,7 @@ public class ArrayELResolver extends ELResolver { if (this.readOnly) { throw new PropertyNotWritableException(Util.message(context, - "resolverNotWriteable", new Object[] { base.getClass() - .getName() })); + "resolverNotWriteable", base.getClass().getName())); } int idx = coerce(property); @@ -96,17 +91,15 @@ public class ArrayELResolver extends ELResolver { if (value != null && !Util.isAssignableFrom(value.getClass(), base.getClass().getComponentType())) { throw new ClassCastException(Util.message(context, - "objectNotAssignable", - new Object[] {value.getClass().getName(), - base.getClass().getComponentType().getName()})); + "objectNotAssignable", value.getClass().getName(), + base.getClass().getComponentType().getName())); } Array.set(base, idx, value); } } @Override - public boolean isReadOnly(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public boolean isReadOnly(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -152,7 +145,7 @@ public class ArrayELResolver extends ELResolver { return ((Character) property).charValue(); } if (property instanceof Boolean) { - return (((Boolean) property).booleanValue() ? 1 : 0); + return ((Boolean) property).booleanValue() ? 1 : 0; } if (property instanceof String) { return Integer.parseInt((String) property); diff --git a/java/javax/el/BeanELResolver.java b/java/javax/el/BeanELResolver.java index a9ba0ab..6ad6af1 100644 --- a/java/javax/el/BeanELResolver.java +++ b/java/javax/el/BeanELResolver.java @@ -70,8 +70,7 @@ public class BeanELResolver extends ELResolver { } @Override - public Class<?> getType(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Class<?> getType(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -84,8 +83,7 @@ public class BeanELResolver extends ELResolver { } @Override - public Object getValue(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Object getValue(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -97,16 +95,9 @@ public class BeanELResolver extends ELResolver { Method m = this.property(context, base, property).read(context); try { return m.invoke(base, (Object[]) null); - } catch (IllegalAccessException e) { - throw new ELException(e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); - if (cause instanceof ThreadDeath) { - throw (ThreadDeath) cause; - } - if (cause instanceof VirtualMachineError) { - throw (VirtualMachineError) cause; - } + Util.handleThrowable(cause); throw new ELException(Util.message(context, "propertyReadError", base.getClass().getName(), property.toString()), cause); } catch (Exception e) { @@ -116,9 +107,7 @@ public class BeanELResolver extends ELResolver { @Override public void setValue(ELContext context, Object base, Object property, - Object value) throws NullPointerException, - PropertyNotFoundException, PropertyNotWritableException, - ELException { + Object value) { if (context == null) { throw new NullPointerException(); } @@ -136,16 +125,9 @@ public class BeanELResolver extends ELResolver { Method m = this.property(context, base, property).write(context); try { m.invoke(base, value); - } catch (IllegalAccessException e) { - throw new ELException(e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); - if (cause instanceof ThreadDeath) { - throw (ThreadDeath) cause; - } - if (cause instanceof VirtualMachineError) { - throw (VirtualMachineError) cause; - } + Util.handleThrowable(cause); throw new ELException(Util.message(context, "propertyWriteError", base.getClass().getName(), property.toString()), cause); } catch (Exception e) { @@ -196,8 +178,7 @@ public class BeanELResolver extends ELResolver { } @Override - public boolean isReadOnly(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public boolean isReadOnly(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -206,8 +187,7 @@ public class BeanELResolver extends ELResolver { } context.setPropertyResolved(true); - return this.readOnly - || this.property(context, base, property).isReadOnly(); + return this.readOnly || this.property(context, base, property).isReadOnly(); } @Override @@ -240,7 +220,7 @@ public class BeanELResolver extends ELResolver { return null; } - protected static final class BeanProperties { + static final class BeanProperties { private final Map<String, BeanProperty> properties; private final Class<?> type; @@ -303,7 +283,7 @@ public class BeanELResolver extends ELResolver { } } - protected static final class BeanProperty { + static final class BeanProperty { private final Class<?> type; private final Class<?> owner; @@ -327,8 +307,8 @@ public class BeanELResolver extends ELResolver { } public boolean isReadOnly() { - return this.write == null - && (null == (this.write = Util.getMethod(this.owner, descriptor.getWriteMethod()))); + return this.write == null && + (null == (this.write = Util.getMethod(this.owner, descriptor.getWriteMethod()))); } public Method getWriteMethod() { @@ -343,7 +323,7 @@ public class BeanELResolver extends ELResolver { if (this.write == null) { this.write = Util.getMethod(this.owner, descriptor.getWriteMethod()); if (this.write == null) { - throw new PropertyNotFoundException(Util.message(ctx, + throw new PropertyNotWritableException(Util.message(ctx, "propertyNotWritable", new Object[] { owner.getName(), descriptor.getName() })); } diff --git a/java/javax/el/CompositeELResolver.java b/java/javax/el/CompositeELResolver.java index e37b5c3..cbe2618 100644 --- a/java/javax/el/CompositeELResolver.java +++ b/java/javax/el/CompositeELResolver.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; import java.beans.FeatureDescriptor; @@ -27,8 +26,7 @@ public class CompositeELResolver extends ELResolver { static { Class<?> clazz = null; try { - clazz = - Class.forName("javax.servlet.jsp.el.ScopedAttributeELResolver"); + clazz = Class.forName("javax.servlet.jsp.el.ScopedAttributeELResolver"); } catch (ClassNotFoundException e) { // Ignore. This is expected if using the EL stand-alone } @@ -58,13 +56,11 @@ public class CompositeELResolver extends ELResolver { } @Override - public Object getValue(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Object getValue(ELContext context, Object base, Object property) { context.setPropertyResolved(false); int sz = this.size; - Object result = null; for (int i = 0; i < sz; i++) { - result = this.resolvers[i].getValue(context, base, property); + Object result = this.resolvers[i].getValue(context, base, property); if (context.isPropertyResolved()) { return result; } @@ -72,99 +68,87 @@ public class CompositeELResolver extends ELResolver { return null; } + /** + * @since EL 2.2 + */ @Override - public void setValue(ELContext context, Object base, Object property, - Object value) throws NullPointerException, - PropertyNotFoundException, PropertyNotWritableException, - ELException { + public Object invoke(ELContext context, Object base, Object method, + Class<?>[] paramTypes, Object[] params) { context.setPropertyResolved(false); int sz = this.size; for (int i = 0; i < sz; i++) { - this.resolvers[i].setValue(context, base, property, value); + Object obj = this.resolvers[i].invoke(context, base, method, paramTypes, params); if (context.isPropertyResolved()) { - return; + return obj; } } + return null; } @Override - public boolean isReadOnly(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Class<?> getType(ELContext context, Object base, Object property) { context.setPropertyResolved(false); int sz = this.size; - boolean readOnly = false; for (int i = 0; i < sz; i++) { - readOnly = this.resolvers[i].isReadOnly(context, base, property); + Class<?> type = this.resolvers[i].getType(context, base, property); if (context.isPropertyResolved()) { - return readOnly; + if (SCOPED_ATTRIBUTE_EL_RESOLVER != null && + SCOPED_ATTRIBUTE_EL_RESOLVER.isAssignableFrom(resolvers[i].getClass())) { + // Special case since + // javax.servlet.jsp.el.ScopedAttributeELResolver will + // always return Object.class for type + Object value = resolvers[i].getValue(context, base, property); + if (value != null) { + return value.getClass(); + } + } + return type; } } - return false; - } - - @Override - public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { - return new FeatureIterator(context, base, this.resolvers, this.size); + return null; } @Override - public Class<?> getCommonPropertyType(ELContext context, Object base) { + public void setValue(ELContext context, Object base, Object property, Object value) { + context.setPropertyResolved(false); int sz = this.size; - Class<?> commonType = null, type = null; for (int i = 0; i < sz; i++) { - type = this.resolvers[i].getCommonPropertyType(context, base); - if (type != null - && (commonType == null || commonType.isAssignableFrom(type))) { - commonType = type; + this.resolvers[i].setValue(context, base, property, value); + if (context.isPropertyResolved()) { + return; } } - return commonType; } @Override - public Class<?> getType(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public boolean isReadOnly(ELContext context, Object base, Object property) { context.setPropertyResolved(false); int sz = this.size; - Class<?> type; for (int i = 0; i < sz; i++) { - type = this.resolvers[i].getType(context, base, property); + boolean readOnly = this.resolvers[i].isReadOnly(context, base, property); if (context.isPropertyResolved()) { - if (SCOPED_ATTRIBUTE_EL_RESOLVER != null && - SCOPED_ATTRIBUTE_EL_RESOLVER.isAssignableFrom( - resolvers[i].getClass())) { - // Special case since - // javax.servlet.jsp.el.ScopedAttributeELResolver will - // always return Object.class for type - Object value = - resolvers[i].getValue(context, base, property); - if (value != null) { - return value.getClass(); - } - } - return type; + return readOnly; } } - return null; + return false; } - /** - * @since EL 2.2 - */ @Override - public Object invoke(ELContext context, Object base, Object method, - Class<?>[] paramTypes, Object[] params) { - context.setPropertyResolved(false); + public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { + return new FeatureIterator(context, base, this.resolvers, this.size); + } + + @Override + public Class<?> getCommonPropertyType(ELContext context, Object base) { + Class<?> commonType = null; int sz = this.size; - Object obj; for (int i = 0; i < sz; i++) { - obj = this.resolvers[i].invoke(context, base, method, paramTypes, - params); - if (context.isPropertyResolved()) { - return obj; + Class<?> type = this.resolvers[i].getCommonPropertyType(context, base); + if (type != null && (commonType == null || commonType.isAssignableFrom(type))) { + commonType = type; } } - return null; + return commonType; } private static final class FeatureIterator implements Iterator<FeatureDescriptor> { @@ -183,8 +167,7 @@ public class CompositeELResolver extends ELResolver { private FeatureDescriptor next; - public FeatureIterator(ELContext context, Object base, - ELResolver[] resolvers, int size) { + public FeatureIterator(ELContext context, Object base, ELResolver[] resolvers, int size) { this.context = context; this.base = base; this.resolvers = resolvers; @@ -196,8 +179,7 @@ public class CompositeELResolver extends ELResolver { private void guaranteeIterator() { while (this.itr == null && this.idx < this.size) { - this.itr = this.resolvers[this.idx].getFeatureDescriptors( - this.context, this.base); + this.itr = this.resolvers[this.idx].getFeatureDescriptors(this.context, this.base); this.idx++; } } @@ -206,7 +188,7 @@ public class CompositeELResolver extends ELResolver { public boolean hasNext() { if (this.next != null) return true; - if (this.itr != null){ + if (this.itr != null) { while (this.next == null && itr.hasNext()) { this.next = itr.next(); } @@ -222,8 +204,9 @@ public class CompositeELResolver extends ELResolver { @Override public FeatureDescriptor next() { - if (!hasNext()) + if (!hasNext()) { throw new NoSuchElementException(); + } FeatureDescriptor result = this.next; this.next = null; return result; @@ -235,5 +218,4 @@ public class CompositeELResolver extends ELResolver { throw new UnsupportedOperationException(); } } - } diff --git a/java/javax/el/ELContext.java b/java/javax/el/ELContext.java index e69612f..11dd984 100644 --- a/java/javax/el/ELContext.java +++ b/java/javax/el/ELContext.java @@ -14,16 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; import java.util.HashMap; import java.util.Locale; import java.util.Map; -/** - * - */ public abstract class ELContext { private Locale locale; @@ -32,32 +28,16 @@ public abstract class ELContext { private boolean resolved; - /** - * - */ public ELContext() { this.resolved = false; } - // Can't use Class<?> because API needs to match specification - /** - * Obtain the context object for the given key. - * - * @param key The key of the required context object - * - * @return The value of the context object associated with the given key - * - * @throws NullPointerException - * If the supplied key is <code>null</code> - */ - public Object getContext(@SuppressWarnings("rawtypes") Class key) { - if (key == null) { - throw new NullPointerException(); - } - if (this.map == null) { - return null; - } - return this.map.get(key); + public void setPropertyResolved(boolean resolved) { + this.resolved = resolved; + } + + public boolean isPropertyResolved() { + return this.resolved; } // Can't use Class<?> because API needs to match specification @@ -71,7 +51,7 @@ public abstract class ELContext { * If the supplied key or context is <code>null</code> */ public void putContext(@SuppressWarnings("rawtypes") Class key, - Object contextObject) throws NullPointerException { + Object contextObject) { if (key == null || contextObject == null) { throw new NullPointerException(); } @@ -83,20 +63,31 @@ public abstract class ELContext { this.map.put(key, contextObject); } - public void setPropertyResolved(boolean resolved) { - this.resolved = resolved; - } - - public boolean isPropertyResolved() { - return this.resolved; + // Can't use Class<?> because API needs to match specification + /** + * Obtain the context object for the given key. + * + * @param key The key of the required context object + * + * @return The value of the context object associated with the given key + * + * @throws NullPointerException + * If the supplied key is <code>null</code> + */ + public Object getContext(@SuppressWarnings("rawtypes") Class key) { + if (key == null) { + throw new NullPointerException(); + } + if (this.map == null) { + return null; + } + return this.map.get(key); } public abstract ELResolver getELResolver(); public abstract FunctionMapper getFunctionMapper(); - public abstract VariableMapper getVariableMapper(); - public Locale getLocale() { return this.locale; } @@ -104,4 +95,6 @@ public abstract class ELContext { public void setLocale(Locale locale) { this.locale = locale; } + + public abstract VariableMapper getVariableMapper(); } diff --git a/java/javax/el/ELException.java b/java/javax/el/ELException.java index c569478..0c26acd 100644 --- a/java/javax/el/ELException.java +++ b/java/javax/el/ELException.java @@ -45,24 +45,24 @@ public class ELException extends RuntimeException { } /** - * Creates an ELException with the given detail message and root cause. + * Creates an ELException with the given cause * - * @param message - * the detail message * @param cause * the originating cause of this exception */ - public ELException(String message, Throwable cause) { - super(message, cause); + public ELException(Throwable cause) { + super(cause); } /** - * Creates an ELException with the given cause + * Creates an ELException with the given detail message and root cause. * + * @param message + * the detail message * @param cause * the originating cause of this exception */ - public ELException(Throwable cause) { - super(cause); + public ELException(String message, Throwable cause) { + super(message, cause); } } diff --git a/java/javax/el/ELResolver.java b/java/javax/el/ELResolver.java index b453254..c43bd73 100644 --- a/java/javax/el/ELResolver.java +++ b/java/javax/el/ELResolver.java @@ -24,11 +24,45 @@ import java.util.Iterator; */ public abstract class ELResolver { + public static final String TYPE = "type"; + public static final String RESOLVABLE_AT_DESIGN_TIME = "resolvableAtDesignTime"; - public static final String TYPE = "type"; + /** + * @param context The EL context for this evaluation + * @param base The base object on which the property is to be found + * @param property The property whose value is to be returned + * @return the value of the provided property + * @throws NullPointerException + * If the supplied context is <code>null</code> + * @throws PropertyNotFoundException + * If the base/property combination provided to the resolver is + * one that the resolver can handle but no match was found or a + * match was found but was not readable + * @throws ELException + * Wraps any exception throw whilst resolving the property + */ + public abstract Object getValue(ELContext context, Object base, + Object property); - public abstract Object getValue(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException; + /** + * Invokes a method on the the given object. This default implementation + * always returns <code>null</code>. + * + * @param context The EL context for this evaluation + * @param base The base object on which the method is to be found + * @param method The method to invoke + * @param paramTypes The types of the parameters of the method to invoke + * @param params The parameters with which to invoke the method + * + * @return Always <code>null</code> + * + * @since EL 2.2 + */ + public Object invoke(ELContext context, Object base, Object method, + Class<?>[] paramTypes, Object[] params) { + return null; + } /** * @param context The EL context for this evaluation @@ -44,7 +78,8 @@ public abstract class ELResolver { * @throws ELException * Wraps any exception throw whilst resolving the property */ - public abstract Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException; + public abstract Class<?> getType(ELContext context, Object base, + Object property); /** * @param context The EL context for this evaluation @@ -63,7 +98,8 @@ public abstract class ELResolver { * @throws ELException * Wraps any exception throw whilst resolving the property */ - public abstract void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException; + public abstract void setValue(ELContext context, Object base, + Object property, Object value); /** * @param context The EL context for this evaluation @@ -79,29 +115,11 @@ public abstract class ELResolver { * @throws ELException * Wraps any exception throw whilst resolving the property */ - public abstract boolean isReadOnly(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException; + public abstract boolean isReadOnly(ELContext context, Object base, + Object property); public abstract Iterator<java.beans.FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base); - public abstract Class<?> getCommonPropertyType(ELContext context, Object base); - - /** - * Invokes a method on the the given object. This default implementation - * always returns <code>null</code>. - * - * @param context The EL context for this evaluation - * @param base The base object on which the method is to be found - * @param method The method to invoke - * @param paramTypes The types of the parameters of the method to invoke - * @param params The parameters with which to invoke the method - * - * @return Always <code>null</code> - * - * @since EL 2.2 - */ - public Object invoke(ELContext context, Object base, Object method, - Class<?>[] paramTypes, Object[] params) { - return null; - } - + public abstract Class<?> getCommonPropertyType(ELContext context, + Object base); } diff --git a/java/javax/el/Expression.java b/java/javax/el/Expression.java index 5c94d22..56286b0 100644 --- a/java/javax/el/Expression.java +++ b/java/javax/el/Expression.java @@ -26,14 +26,14 @@ public abstract class Expression implements Serializable { private static final long serialVersionUID = -6663767980471823812L; + public abstract String getExpressionString(); + @Override public abstract boolean equals(Object obj); @Override public abstract int hashCode(); - public abstract String getExpressionString(); - public abstract boolean isLiteralText(); } diff --git a/java/javax/el/ExpressionFactory.java b/java/javax/el/ExpressionFactory.java index 33c7e6a..f8853d5 100644 --- a/java/javax/el/ExpressionFactory.java +++ b/java/javax/el/ExpressionFactory.java @@ -54,8 +54,8 @@ public abstract class ExpressionFactory { private static final String PROPERTY_FILE; private static final CacheValue nullTcclFactory = new CacheValue(); - private static ConcurrentMap<CacheKey, CacheValue> factoryCache - = new ConcurrentHashMap<CacheKey, CacheValue>(); + private static ConcurrentMap<CacheKey, CacheValue> factoryCache = + new ConcurrentHashMap<CacheKey, CacheValue>(); static { if (IS_SECURITY_ENABLED) { @@ -76,64 +76,6 @@ public abstract class ExpressionFactory { } /** - * Coerce the supplied object to the requested type. - * - * @param obj The object to be coerced - * @param expectedType The type to which the object should be coerced - * - * @return An instance of the requested type. - * - * @throws ELException - * If the conversion fails - */ - public abstract Object coerceToType(Object obj, Class<?> expectedType) - throws ELException; - - /** - * Create a new value expression. - * - * @param context The EL context for this evaluation - * @param expression The String representation of the value expression - * @param expectedType The expected type of the result of evaluating the - * expression - * - * @return A new value expression formed from the input parameters - * - * @throws NullPointerException - * If the expected type is <code>null</code> - * @throws ELException - * If there are syntax errors in the provided expression - */ - public abstract ValueExpression createValueExpression(ELContext context, - String expression, Class<?> expectedType) - throws NullPointerException, ELException; - - public abstract ValueExpression createValueExpression(Object instance, - Class<?> expectedType); - - /** - * Create a new method expression instance. - * - * @param context The EL context for this evaluation - * @param expression The String representation of the method - * expression - * @param expectedReturnType The expected type of the result of invoking the - * method - * @param expectedParamTypes The expected types of the input parameters - * - * @return A new method expression formed from the input parameters. - * - * @throws NullPointerException - * If the expected parameters types are <code>null</code> - * @throws ELException - * If there are syntax errors in the provided expression - */ - public abstract MethodExpression createMethodExpression(ELContext context, - String expression, Class<?> expectedReturnType, - Class<?>[] expectedParamTypes) throws ELException, - NullPointerException; - - /** * Create a new {@link ExpressionFactory}. The class to use is determined by * the following search order: * <ol> @@ -207,9 +149,7 @@ public abstract class ExpressionFactory { writeLock.unlock(); } } catch (ClassNotFoundException e) { - throw new ELException( - "Unable to find ExpressionFactory of type: " + className, - e); + throw new ELException(Util.message(null, "expressionFactory.cannotFind", className), e); } } @@ -227,44 +167,85 @@ public abstract class ExpressionFactory { } } if (constructor == null) { - result = (ExpressionFactory) clazz.getDeclaredConstructor().newInstance(); + result = (ExpressionFactory) clazz.getConstructor().newInstance(); } else { result = (ExpressionFactory) constructor.newInstance(properties); } + + } catch (InvocationTargetException e) { + Throwable cause = e.getCause(); + Util.handleThrowable(cause); + throw new ELException(Util.message(null, "expressionFactory.cannotCreate", clazz.getName()), e); } catch (InstantiationException e) { - throw new ELException( - "Unable to create ExpressionFactory of type: " + clazz.getName(), - e); + throw new ELException(Util.message(null, "expressionFactory.cannotCreate", clazz.getName()), e); } catch (IllegalAccessException e) { - throw new ELException( - "Unable to create ExpressionFactory of type: " + clazz.getName(), - e); + throw new ELException(Util.message(null, "expressionFactory.cannotCreate", clazz.getName()), e); } catch (IllegalArgumentException e) { - throw new ELException( - "Unable to create ExpressionFactory of type: " + clazz.getName(), - e); + throw new ELException(Util.message(null, "expressionFactory.cannotCreate", clazz.getName()), e); } catch (NoSuchMethodException e) { - throw new ELException( - "Unable to create ExpressionFactory of type: " + clazz.getName(), - e); - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - if (cause instanceof ThreadDeath) { - throw (ThreadDeath) cause; - } - if (cause instanceof VirtualMachineError) { - throw (VirtualMachineError) cause; - } - throw new ELException( - "Unable to create ExpressionFactory of type: " + clazz.getName(), - e); + throw new ELException(Util.message(null, "expressionFactory.cannotCreate", clazz.getName()), e); } return result; } /** + * Create a new value expression. + * + * @param context The EL context for this evaluation + * @param expression The String representation of the value expression + * @param expectedType The expected type of the result of evaluating the + * expression + * + * @return A new value expression formed from the input parameters + * + * @throws NullPointerException + * If the expected type is <code>null</code> + * @throws ELException + * If there are syntax errors in the provided expression + */ + public abstract ValueExpression createValueExpression(ELContext context, + String expression, Class<?> expectedType); + + public abstract ValueExpression createValueExpression(Object instance, + Class<?> expectedType); + + /** + * Create a new method expression instance. + * + * @param context The EL context for this evaluation + * @param expression The String representation of the method + * expression + * @param expectedReturnType The expected type of the result of invoking the + * method + * @param expectedParamTypes The expected types of the input parameters + * + * @return A new method expression formed from the input parameters. + * + * @throws NullPointerException + * If the expected parameters types are <code>null</code> + * @throws ELException + * If there are syntax errors in the provided expression + */ + public abstract MethodExpression createMethodExpression(ELContext context, + String expression, Class<?> expectedReturnType, + Class<?>[] expectedParamTypes); + + /** + * Coerce the supplied object to the requested type. + * + * @param obj The object to be coerced + * @param expectedType The type to which the object should be coerced + * + * @return An instance of the requested type. + * + * @throws ELException + * If the conversion fails + */ + public abstract Object coerceToType(Object obj, Class<?> expectedType); + + /** * Key used to cache ExpressionFactory discovery information per class * loader. The class loader reference is never {@code null}, because * {@code null} tccl is handled separately. @@ -401,8 +382,7 @@ public abstract class ExpressionFactory { // Should never happen with UTF-8 // If it does - ignore & return null } catch (IOException e) { - throw new ELException("Failed to read " + SERVICE_RESOURCE_NAME, - e); + throw new ELException(Util.message(null, "expressionFactory.readFailed", SERVICE_RESOURCE_NAME), e); } finally { try { if (br != null) { @@ -438,7 +418,7 @@ public abstract class ExpressionFactory { } catch (FileNotFoundException e) { // Should not happen - ignore it if it does } catch (IOException e) { - throw new ELException("Failed to read " + PROPERTY_FILE, e); + throw new ELException(Util.message(null, "expressionFactory.readFailed", PROPERTY_FILE), e); } finally { if (is != null) { try { diff --git a/java/javax/el/FunctionMapper.java b/java/javax/el/FunctionMapper.java index edf24e2..aec10ee 100644 --- a/java/javax/el/FunctionMapper.java +++ b/java/javax/el/FunctionMapper.java @@ -14,16 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; import java.lang.reflect.Method; -/** - * - */ public abstract class FunctionMapper { public abstract Method resolveFunction(String prefix, String localName); - } diff --git a/java/javax/el/ListELResolver.java b/java/javax/el/ListELResolver.java index caf21d4..49b67ea 100644 --- a/java/javax/el/ListELResolver.java +++ b/java/javax/el/ListELResolver.java @@ -39,8 +39,7 @@ public class ListELResolver extends ELResolver { } @Override - public Object getValue(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Class<?> getType(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -50,17 +49,17 @@ public class ListELResolver extends ELResolver { List<?> list = (List<?>) base; int idx = coerce(property); if (idx < 0 || idx >= list.size()) { - return null; + throw new PropertyNotFoundException( + new ArrayIndexOutOfBoundsException(idx).getMessage()); } - return list.get(idx); + return Object.class; } return null; } @Override - public Class<?> getType(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Object getValue(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -70,10 +69,9 @@ public class ListELResolver extends ELResolver { List<?> list = (List<?>) base; int idx = coerce(property); if (idx < 0 || idx >= list.size()) { - throw new PropertyNotFoundException( - new ArrayIndexOutOfBoundsException(idx).getMessage()); + return null; } - return Object.class; + return list.get(idx); } return null; @@ -81,9 +79,7 @@ public class ListELResolver extends ELResolver { @Override public void setValue(ELContext context, Object base, Object property, - Object value) throws NullPointerException, - PropertyNotFoundException, PropertyNotWritableException, - ELException { + Object value) { if (context == null) { throw new NullPointerException(); } @@ -95,8 +91,7 @@ public class ListELResolver extends ELResolver { if (this.readOnly) { throw new PropertyNotWritableException(Util.message(context, - "resolverNotWriteable", new Object[] { base.getClass() - .getName() })); + "resolverNotWriteable", base.getClass().getName())); } int idx = coerce(property); @@ -111,8 +106,7 @@ public class ListELResolver extends ELResolver { } @Override - public boolean isReadOnly(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public boolean isReadOnly(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -157,7 +151,7 @@ public class ListELResolver extends ELResolver { return ((Character) property).charValue(); } if (property instanceof Boolean) { - return (((Boolean) property).booleanValue() ? 1 : 0); + return ((Boolean) property).booleanValue() ? 1 : 0; } if (property instanceof String) { return Integer.parseInt((String) property); diff --git a/java/javax/el/LocalStrings.properties b/java/javax/el/LocalStrings.properties index 3507c20..e2a56fa 100644 --- a/java/javax/el/LocalStrings.properties +++ b/java/javax/el/LocalStrings.properties @@ -13,12 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +expressionFactory.cannotCreate=Unable to create ExpressionFactory of type [{0}] +expressionFactory.cannotFind=Unable to find ExpressionFactory of type [{0}] +expressionFactory.readFailed=Failed to read [{0}] + objectNotAssignable=Unable to add an object of type [{0}] to an array of objects of type [{1}] -propertyNotFound=Property ''{1}'' not found on type {0} -propertyNotReadable=Property ''{1}'' not readable on type {0} -propertyNotWritable=Property ''{1}'' not writable on type {0} -propertyReadError=Error reading ''{1}'' on type {0} -propertyWriteError=Error writing ''{1}'' on type {0} +propertyNotFound=Property [{1}] not found on type [{0}] +propertyNotReadable=Property [{1}] not readable on type [{0}] +propertyNotWritable=Property [{1}] not writable on type [{0}] +propertyReadError=Error reading [{1}] on type [{0}] +propertyWriteError=Error writing [{1}] on type [{0}] util.method.ambiguous=Unable to find unambiguous method: {0}.{1}({2}) util.method.notfound=Method not found: {0}.{1}({2}) diff --git a/java/javax/el/LocalStrings_es.properties b/java/javax/el/LocalStrings_es.properties index 82f0486..7a71ca2 100644 --- a/java/javax/el/LocalStrings_es.properties +++ b/java/javax/el/LocalStrings_es.properties @@ -14,8 +14,8 @@ # limitations under the License. objectNotAssignable=No puedo aƱadir un objeto del tipo [{0}] a un arreglo de objetos del tipo [{1}] -propertyNotFound=Propiedad ''{1}'' no hallada en el tipo {0} -propertyNotReadable=Propiedad ''{1}'' no legible para el tipo {0} -propertyNotWritable=Propiedad ''{1}'' no grabable para el tipo {0} -propertyReadError=Error reading ''{1}'' en el tipo {0} -propertyWriteError=Error writing ''{1}'' en el tipo {0} +propertyNotFound=Propiedad [{1}] no hallada en el tipo [{0}] +propertyNotReadable=Propiedad [{1}] no legible para el tipo [{0}] +propertyNotWritable=Propiedad [{1}] no grabable para el tipo [{0}] +propertyReadError=Error reading [{1}] en el tipo [{0}] +propertyWriteError=Error writing [{1}] en el tipo [{0}] diff --git a/java/javax/el/MapELResolver.java b/java/javax/el/MapELResolver.java index 2e345b1..603cae8 100644 --- a/java/javax/el/MapELResolver.java +++ b/java/javax/el/MapELResolver.java @@ -41,30 +41,28 @@ public class MapELResolver extends ELResolver { } @Override - public Object getValue(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Class<?> getType(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } if (base instanceof Map<?,?>) { context.setPropertyResolved(true); - return ((Map<?,?>) base).get(property); + return Object.class; } return null; } @Override - public Class<?> getType(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Object getValue(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } if (base instanceof Map<?,?>) { context.setPropertyResolved(true); - return Object.class; + return ((Map<?,?>) base).get(property); } return null; @@ -72,9 +70,7 @@ public class MapELResolver extends ELResolver { @Override public void setValue(ELContext context, Object base, Object property, - Object value) throws NullPointerException, - PropertyNotFoundException, PropertyNotWritableException, - ELException { + Object value) { if (context == null) { throw new NullPointerException(); } @@ -84,8 +80,7 @@ public class MapELResolver extends ELResolver { if (this.readOnly) { throw new PropertyNotWritableException(Util.message(context, - "resolverNotWriteable", new Object[] { base.getClass() - .getName() })); + "resolverNotWriteable", base.getClass().getName())); } try { @@ -99,8 +94,7 @@ public class MapELResolver extends ELResolver { } @Override - public boolean isReadOnly(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public boolean isReadOnly(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } diff --git a/java/javax/el/MethodExpression.java b/java/javax/el/MethodExpression.java index abd85ef..8cba354 100644 --- a/java/javax/el/MethodExpression.java +++ b/java/javax/el/MethodExpression.java @@ -14,12 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; -/** - * - */ public abstract class MethodExpression extends Expression { private static final long serialVersionUID = 8163925562047324656L; @@ -39,7 +35,7 @@ public abstract class MethodExpression extends Expression { * @throws ELException * Wraps any exception throw whilst resolving the property */ - public abstract MethodInfo getMethodInfo(ELContext context) throws NullPointerException, PropertyNotFoundException, MethodNotFoundException, ELException; + public abstract MethodInfo getMethodInfo(ELContext context); /** * @param context The EL context for this evaluation @@ -58,7 +54,7 @@ public abstract class MethodExpression extends Expression { * Wraps any exception throw whilst resolving the property or * coercion of the result to the expected return type fails */ - public abstract Object invoke(ELContext context, Object[] params) throws NullPointerException, PropertyNotFoundException, MethodNotFoundException, ELException; + public abstract Object invoke(ELContext context, Object[] params); /** * @since EL 2.2 diff --git a/java/javax/el/MethodInfo.java b/java/javax/el/MethodInfo.java index dff61f7..2ee7bec 100644 --- a/java/javax/el/MethodInfo.java +++ b/java/javax/el/MethodInfo.java @@ -14,12 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; -/** - * - */ public class MethodInfo { private final String name; @@ -28,9 +24,6 @@ public class MethodInfo { private final Class<?> returnType; - /** - * - */ public MethodInfo(String name, Class<?> returnType, Class<?>[] paramTypes) { this.name = name; this.returnType = returnType; @@ -41,12 +34,11 @@ public class MethodInfo { return this.name; } - public Class<?>[] getParamTypes() { - return this.paramTypes; - } - public Class<?> getReturnType() { return this.returnType; } + public Class<?>[] getParamTypes() { + return this.paramTypes; + } } diff --git a/java/javax/el/MethodNotFoundException.java b/java/javax/el/MethodNotFoundException.java index 8d4a835..8159331 100644 --- a/java/javax/el/MethodNotFoundException.java +++ b/java/javax/el/MethodNotFoundException.java @@ -14,42 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; -/** - * - */ public class MethodNotFoundException extends ELException { private static final long serialVersionUID = -3631968116081480328L; - /** - * - */ public MethodNotFoundException() { super(); } - /** - * @param message - */ public MethodNotFoundException(String message) { super(message); } - /** - * @param message - * @param cause - */ - public MethodNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param cause - */ public MethodNotFoundException(Throwable cause) { super(cause); } + + public MethodNotFoundException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/java/javax/el/PropertyNotFoundException.java b/java/javax/el/PropertyNotFoundException.java index 28b7f94..9ed8188 100644 --- a/java/javax/el/PropertyNotFoundException.java +++ b/java/javax/el/PropertyNotFoundException.java @@ -14,43 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; -/** - * - */ public class PropertyNotFoundException extends ELException { private static final long serialVersionUID = -3799200961303506745L; - /** - * - */ public PropertyNotFoundException() { super(); } - /** - * @param message - */ public PropertyNotFoundException(String message) { super(message); } - /** - * @param message - * @param cause - */ - public PropertyNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param cause - */ public PropertyNotFoundException(Throwable cause) { super(cause); } + public PropertyNotFoundException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/java/javax/el/PropertyNotWritableException.java b/java/javax/el/PropertyNotWritableException.java index fc9f644..30b7857 100644 --- a/java/javax/el/PropertyNotWritableException.java +++ b/java/javax/el/PropertyNotWritableException.java @@ -14,42 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; -/** - * - */ public class PropertyNotWritableException extends ELException { private static final long serialVersionUID = 827987155471214717L; - /** - * - */ public PropertyNotWritableException() { super(); } - /** - * @param message - */ public PropertyNotWritableException(String message) { super(message); } - /** - * @param message - * @param cause - */ - public PropertyNotWritableException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param cause - */ public PropertyNotWritableException(Throwable cause) { super(cause); } + + public PropertyNotWritableException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/java/javax/el/ResourceBundleELResolver.java b/java/javax/el/ResourceBundleELResolver.java index 101a62f..374968e 100644 --- a/java/javax/el/ResourceBundleELResolver.java +++ b/java/javax/el/ResourceBundleELResolver.java @@ -32,10 +32,7 @@ public class ResourceBundleELResolver extends ELResolver { } @Override - public Object getValue(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, - ELException { - + public Object getValue(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -57,8 +54,7 @@ public class ResourceBundleELResolver extends ELResolver { } @Override - public Class<?> getType(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public Class<?> getType(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } @@ -72,9 +68,7 @@ public class ResourceBundleELResolver extends ELResolver { @Override public void setValue(ELContext context, Object base, Object property, - Object value) throws NullPointerException, - PropertyNotFoundException, PropertyNotWritableException, - ELException { + Object value) { if (context == null) { throw new NullPointerException(); } @@ -82,14 +76,12 @@ public class ResourceBundleELResolver extends ELResolver { if (base instanceof ResourceBundle) { context.setPropertyResolved(true); throw new PropertyNotWritableException(Util.message(context, - "resolverNotWriteable", new Object[] { base.getClass() - .getName() })); + "resolverNotWriteable", base.getClass().getName())); } } @Override - public boolean isReadOnly(ELContext context, Object base, Object property) - throws NullPointerException, PropertyNotFoundException, ELException { + public boolean isReadOnly(ELContext context, Object base, Object property) { if (context == null) { throw new NullPointerException(); } diff --git a/java/javax/el/ValueExpression.java b/java/javax/el/ValueExpression.java index a84ae5a..1816f9d 100644 --- a/java/javax/el/ValueExpression.java +++ b/java/javax/el/ValueExpression.java @@ -14,22 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; -/** - * - */ public abstract class ValueExpression extends Expression { private static final long serialVersionUID = 8577809572381654673L; - public abstract Class<?> getExpectedType(); - /** * @param context The EL context for this evaluation * - * @return The type of the result of this value expression + * @return The result of evaluating this value expression * * @throws NullPointerException * If the supplied context is <code>null</code> @@ -40,48 +34,48 @@ public abstract class ValueExpression extends Expression { * Wraps any exception throw whilst resolving a property or * variable */ - public abstract Class<?> getType(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException; + public abstract Object getValue(ELContext context); /** * @param context The EL context for this evaluation - * - * @return <code>true</code> if this expression is read only otherwise - * <code>false</code> + * @param value The value to set the property to which this value + * expression refers * * @throws NullPointerException * If the supplied context is <code>null</code> * @throws PropertyNotFoundException * If a property/variable resolution failed because no match - * was found or a match was found but was not readable + * was found + * @throws PropertyNotWritableException + * If a property/variable resolution failed because a match was + * found but was not writable * @throws ELException * Wraps any exception throw whilst resolving a property or * variable */ - public abstract boolean isReadOnly(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException; + public abstract void setValue(ELContext context, Object value); /** * @param context The EL context for this evaluation - * @param value The value to set the property to which this value - * expression refers + * + * @return <code>true</code> if this expression is read only otherwise + * <code>false</code> * * @throws NullPointerException * If the supplied context is <code>null</code> * @throws PropertyNotFoundException * If a property/variable resolution failed because no match - * was found - * @throws PropertyNotWritableException - * If a property/variable resolution failed because a match was - * found but was not writable + * was found or a match was found but was not readable * @throws ELException * Wraps any exception throw whilst resolving a property or * variable */ - public abstract void setValue(ELContext context, Object value) throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException; + public abstract boolean isReadOnly(ELContext context); /** * @param context The EL context for this evaluation * - * @return The result of evaluating this value expression + * @return The type of the result of this value expression * * @throws NullPointerException * If the supplied context is <code>null</code> @@ -92,7 +86,9 @@ public abstract class ValueExpression extends Expression { * Wraps any exception throw whilst resolving a property or * variable */ - public abstract Object getValue(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException; + public abstract Class<?> getType(ELContext context); + + public abstract Class<?> getExpectedType(); /** * @param context The EL context for this evaluation --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org