Class OgnlRuntime

java.lang.Object
ognl.OgnlRuntime

public class OgnlRuntime extends Object
Utility class used by internal OGNL API to do various things like:
  • Field Details

    • NotFound

      public static final Object NotFound
      Constant expression used to indicate that a given method / property couldn't be found during reflection operations.
    • NoArguments

      public static final Object[] NoArguments
    • NoConversionPossible

      public static final Object NoConversionPossible
      Token returned by TypeConverter for no conversion possible
    • INDEXED_PROPERTY_NONE

      public static int INDEXED_PROPERTY_NONE
      Not an indexed property
    • INDEXED_PROPERTY_INT

      public static int INDEXED_PROPERTY_INT
      JavaBeans IndexedProperty
    • INDEXED_PROPERTY_OBJECT

      public static int INDEXED_PROPERTY_OBJECT
      OGNL ObjectIndexedProperty
    • NULL_STRING

      public static final String NULL_STRING
      Constant string representation of null string.
    • SET_PREFIX

      public static final String SET_PREFIX
      Java beans standard set method prefix.
      See Also:
    • GET_PREFIX

      public static final String GET_PREFIX
      Java beans standard get method prefix.
      See Also:
    • IS_PREFIX

      public static final String IS_PREFIX
      Java beans standard is<Foo> boolean getter prefix.
      See Also:
    • NoArgsReport

      public static final OgnlRuntime.ArgsCompatbilityReport NoArgsReport
  • Constructor Details

    • OgnlRuntime

      public OgnlRuntime()
  • Method Details

    • clearCache

      public static void clearCache()
      Clears all of the cached reflection information normally used to improve the speed of expressions that operate on the same classes or are executed multiple times.

      Warning: Calling this too often can be a huge performance drain on your expressions - use with care.

    • clearAdditionalCache

      public static void clearAdditionalCache()
      Clears some additional caches used by OgnlRuntime. The existing clearCache() clears the standard reflection-related caches, but some applications may have need to clear the additional caches as well.

      Clearing the additional caches may have greater impact than the clearCache() method so it should only be used when the normal cache clear is insufficient.

      Warning: Calling this method too often can be a huge performance drain on your expressions - use with care.

      Since:
      3.1.25
    • getMajorJavaVersion

      public static int getMajorJavaVersion()
      Get the Major Java Version detected by OGNL.
      Returns:
      Detected Major Java Version, or 5 (minimum supported version for OGNL) if unable to detect.
    • isJdk9Plus

      @Deprecated public static boolean isJdk9Plus()
      Deprecated.
      since 3.4.6, forRemoval = true
      Check if the detected Major Java Version is 9 or higher (JDK 9+).
      Returns:
      Return true if the Detected Major Java version is 9 or higher, otherwise false.
    • getNumericValueGetter

      public static String getNumericValueGetter(Class<?> type)
    • getPrimitiveWrapperClass

      public static Class<?> getPrimitiveWrapperClass(Class<?> primitiveClass)
    • getNumericCast

      public static String getNumericCast(Class<? extends Number> type)
    • getNumericLiteral

      public static String getNumericLiteral(Class<?> type)
    • setCompiler

      public static void setCompiler(OgnlExpressionCompiler compiler)
    • getCompiler

      public static OgnlExpressionCompiler getCompiler()
    • compileExpression

      public static void compileExpression(OgnlContext context, Node expression, Object root) throws Exception
      Throws:
      Exception
    • getTargetClass

      public static Class<?> getTargetClass(Object o)
      Gets the "target" class of an object for looking up accessors that are registered on the target. If the object is a Class object this will return the Class itself, else it will return object's getClass() result.
      Parameters:
      o - the Object from which to retrieve its Class.
      Returns:
      the Class of o.
    • getBaseName

      public static String getBaseName(Object o)
      Returns the base name (the class name without the package name prepended) of the object given.
      Parameters:
      o - the Object from which to retrieve its base classname.
      Returns:
      the base classname of o's Class.
    • getClassBaseName

      public static String getClassBaseName(Class<?> c)
      Returns the base name (the class name without the package name prepended) of the class given.
      Parameters:
      c - the Class from which to retrieve its name.
      Returns:
      the base classname of c.
    • getClassName

      public static String getClassName(Object o, boolean fullyQualified)
    • getClassName

      public static String getClassName(Class<?> c, boolean fullyQualified)
    • getPackageName

      public static String getPackageName(Object o)
      Returns the package name of the object's class.
      Parameters:
      o - the Object from which to retrieve its Class package name.
      Returns:
      the package name of o's Class.
    • getClassPackageName

      public static String getClassPackageName(Class<?> c)
      Returns the package name of the class given.
      Parameters:
      c - the Class from which to retrieve its package name.
      Returns:
      the package name of c.
    • getPointerString

      public static String getPointerString(int num)
      Returns a "pointer" string in the usual format for these things - 0x<hex digits>.
      Parameters:
      num - the int to convert into a "pointer" string in hex format.
      Returns:
      the String representing num as a "pointer" string in hex format.
    • getPointerString

      public static String getPointerString(Object o)
      Returns a "pointer" string in the usual format for these things - 0x<hex digits> for the object given. This will always return a unique value for each object.
      Parameters:
      o - the Object to convert into a "pointer" string in hex format.
      Returns:
      the String representing o as a "pointer" string in hex format.
    • getUniqueDescriptor

      public static String getUniqueDescriptor(Object object, boolean fullyQualified)
      Returns a unique descriptor string that includes the object's class and a unique integer identifier. If fullyQualified is true then the class name will be fully qualified to include the package name, else it will be just the class' base name.
      Parameters:
      object - the Object for which a unique descriptor string is desired.
      fullyQualified - true if the descriptor string is fully-qualified (package name), false for just the Class' base name.
      Returns:
      the unique descriptor String for the object, qualified as per fullyQualified parameter.
    • getUniqueDescriptor

      public static String getUniqueDescriptor(Object object)
      Returns a unique descriptor string that includes the object's class' base name and a unique integer identifier.
      Parameters:
      object - the Object for which a unique descriptor string is desired.
      Returns:
      the unique descriptor String for the object, NOT fully-qualified.
    • getParameterTypes

      public static Class<?>[] getParameterTypes(Method method) throws CacheException
      Returns the parameter types of the given method.
      Parameters:
      method - the Method whose parameter types are being queried.
      Returns:
      the array of Class elements representing m's parameters. May be null if m does not utilize parameters.
      Throws:
      CacheException
    • findParameterTypes

      public static Class<?>[] findParameterTypes(Class<?> type, Method method)
      Finds the appropriate parameter types for the given Method and Class instance of the type the method is associated with. Correctly finds generic types if running in >= 1.5 jre as well.
      Parameters:
      type - The class type the method is being executed against.
      method - The method to find types for.
      Returns:
      Array of parameter types for the given method.
    • getParameterTypes

      public static Class<?>[] getParameterTypes(Constructor<?> constructor) throws CacheException
      Returns the parameter types of the given method.
      Parameters:
      constructor - the Constructor whose parameter types are being queried.
      Returns:
      the array of Class elements representing c's parameters. May be null if c does not utilize parameters.
      Throws:
      CacheException
    • getSecurityManager

      @Deprecated public static SecurityManager getSecurityManager()
      Deprecated.
      will be removed in 3.5.x
      Gets the SecurityManager that OGNL uses to determine permissions for invoking methods.
      Returns:
      SecurityManager for OGNL
    • setSecurityManager

      @Deprecated public static void setSecurityManager(SecurityManager value)
      Deprecated.
      will be removed in 3.5.x
      Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.
      Parameters:
      value - SecurityManager to set
    • getPermission

      @Deprecated public static Permission getPermission(Method method) throws CacheException
      Deprecated.
      since 3.4.6, forRemoval = true
      Permission will be named "invoke.<declaring-class>.<method-name>".
      Parameters:
      method - the Method whose Permission is being requested.
      Returns:
      the Permission for method named "invoke.<declaring-class>.<method-name>".
      Throws:
      CacheException
    • invokeMethod

      public static Object invokeMethod(Object target, Method method, Object[] argsArray) throws InvocationTargetException, IllegalAccessException
      Throws:
      InvocationTargetException
      IllegalAccessException
    • getArgClass

      public static Class<?> getArgClass(Object arg)
      Gets the class for a method argument that is appropriate for looking up methods by reflection, by looking for the standard primitive wrapper classes and exchanging for them their underlying primitive class objects. Other classes are passed through unchanged.
      Parameters:
      arg - an object that is being passed to a method
      Returns:
      the class to use to look up the method
    • getArgClasses

      public static Class<?>[] getArgClasses(Object[] args)
    • isTypeCompatible

      public static boolean isTypeCompatible(Object object, Class<?> c)
      Tells whether the given object is compatible with the given class ---that is, whether the given object can be passed as an argument to a method or constructor whose parameter type is the given class. If object is null this will return true because null is compatible with any type.
      Parameters:
      object - the Object to check for type-compatibility with Class c.
      c - the Class for which object's type-compatibility is being checked.
      Returns:
      true if object is type-compatible with c.
    • isTypeCompatible

      public static boolean isTypeCompatible(Class<?> parameterClass, Class<?> methodArgumentClass, int index, OgnlRuntime.ArgsCompatbilityReport report)
    • areArgsCompatible

      public static boolean areArgsCompatible(Object[] args, Class<?>[] classes)
    • areArgsCompatible

      public static OgnlRuntime.ArgsCompatbilityReport areArgsCompatible(Class<?>[] args, Class<?>[] classes, Method m)
    • isMoreSpecific

      public static boolean isMoreSpecific(Class<?>[] classes1, Class<?>[] classes2)
      Tells whether the first array of classes is more specific than the second. Assumes that the two arrays are of the same length.
      Parameters:
      classes1 - the Class array being checked to see if it is "more specific" than classes2.
      classes2 - the Class array that classes1 is being checked against to see if classes1 is "more specific" than classes2.
      Returns:
      true if the classes1 Class contents are "more specific" than classes2 Class contents, false otherwise.
    • getModifierString

      public static String getModifierString(int modifiers)
    • classForName

      public static <T> Class<T> classForName(OgnlContext context, String className) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • isInstance

      public static boolean isInstance(OgnlContext context, Object value, String className) throws OgnlException
      Throws:
      OgnlException
    • getPrimitiveDefaultValue

      public static Object getPrimitiveDefaultValue(Class<?> forClass)
    • getNumericDefaultValue

      public static Object getNumericDefaultValue(Class<?> forClass)
    • getConvertedType

      public static Object getConvertedType(OgnlContext context, Object target, Member member, String propertyName, Object value, Class<?> type)
    • getConvertedTypes

      public static boolean getConvertedTypes(OgnlContext context, Object target, Member member, String propertyName, Class<?>[] parameterTypes, Object[] args, Object[] newArgs)
    • getConvertedConstructorAndArgs

      public static Constructor<?> getConvertedConstructorAndArgs(OgnlContext context, Object target, List<Constructor<?>> constructors, Object[] args, Object[] newArgs)
    • getAppropriateMethod

      public static Method getAppropriateMethod(OgnlContext context, Object source, Object target, String propertyName, String methodName, List<Method> methods, Object[] args, Object[] actualArgs)
      Gets the appropriate method to be called for the given target, method name and arguments. If successful this method will return the Method within the target that can be called and the converted arguments in actualArgs. If unsuccessful this method will return null and the actualArgs will be empty.
      Parameters:
      context - The current execution context.
      source - Target object to run against or method name.
      target - Instance of object to be run against.
      propertyName - Name of property to get method of.
      methodName - Name of the method to get from known methods.
      methods - List of current known methods.
      args - Arguments originally passed in.
      actualArgs - Converted arguments.
      Returns:
      Best method match or null if none could be found.
    • getConvertedMethodAndArgs

      public static Method getConvertedMethodAndArgs(OgnlContext context, Object target, String propertyName, List<Method> methods, Object[] args, Object[] newArgs)
    • callAppropriateMethod

      public static Object callAppropriateMethod(OgnlContext context, Object source, Object target, String methodName, String propertyName, List<Method> methods, Object[] args) throws MethodFailedException
      Throws:
      MethodFailedException
    • callStaticMethod

      public static Object callStaticMethod(OgnlContext context, String className, String methodName, Object[] args) throws OgnlException
      Throws:
      OgnlException
    • callMethod

      public static Object callMethod(OgnlContext context, Object target, String methodName, String propertyName, Object[] args) throws OgnlException
      Invokes the specified method against the target object.
      Parameters:
      context - The current execution context.
      target - The object to invoke the method on.
      methodName - Name of the method - as in "getValue" or "add", etc..
      propertyName - Name of the property to call instead?
      args - Optional arguments needed for method.
      Returns:
      Result of invoking method.
      Throws:
      OgnlException - For lots of different reasons.
    • callMethod

      public static Object callMethod(OgnlContext context, Object target, String methodName, Object[] args) throws OgnlException
      Invokes the specified method against the target object.
      Parameters:
      context - The current execution context.
      target - The object to invoke the method on.
      methodName - Name of the method - as in "getValue" or "add", etc..
      args - Optional arguments needed for method.
      Returns:
      Result of invoking method.
      Throws:
      OgnlException - For lots of different reasons.
    • callConstructor

      public static Object callConstructor(OgnlContext context, String className, Object[] args) throws OgnlException
      Throws:
      OgnlException
    • getMethodValue

      @Deprecated public static Object getMethodValue(OgnlContext context, Object target, String propertyName) throws OgnlException, IllegalAccessException, NoSuchMethodException, IntrospectionException
      Deprecated.
      Don't use this method as it doesn't check member access rights via MemberAccess interface
      Parameters:
      context - the current execution context.
      target - the object to invoke the property name get on.
      propertyName - the name of the property to be retrieved from target.
      Returns:
      the result invoking property retrieval of propertyName for target.
      Throws:
      OgnlException - for lots of different reasons.
      IllegalAccessException - if access not permitted.
      NoSuchMethodException - if no property accessor exists.
      IntrospectionException - on errors using Introspector.
    • getMethodValue

      public static Object getMethodValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) throws OgnlException, IllegalAccessException, NoSuchMethodException
      If the checkAccessAndExistence flag is true this method will check to see if the method exists and if it is accessible according to the context's MemberAccess. If neither test passes this will return NotFound.
      Parameters:
      context - the current execution context.
      target - the object to invoke the property name get on.
      propertyName - the name of the property to be retrieved from target.
      checkAccessAndExistence - true if this method should check access levels and existence for propertyName of target, false otherwise.
      Returns:
      the result invoking property retrieval of propertyName for target.
      Throws:
      OgnlException - for lots of different reasons.
      IllegalAccessException - if access not permitted.
      NoSuchMethodException - if no property accessor exists.
    • setMethodValue

      @Deprecated public static boolean setMethodValue(OgnlContext context, Object target, String propertyName, Object value) throws OgnlException
      Deprecated.
      Don't use this method as it doesn't check member access rights via MemberAccess interface
      Parameters:
      context - the current execution context.
      target - the object to invoke the property name get on.
      propertyName - the name of the property to be set for target.
      value - the value to set for propertyName of target.
      Returns:
      true if the operation succeeded, false otherwise.
      Throws:
      OgnlException - for lots of different reasons.
    • setMethodValue

      public static boolean setMethodValue(OgnlContext context, Object target, String propertyName, Object value, boolean checkAccessAndExistence) throws OgnlException
      Throws:
      OgnlException
    • getConstructors

      public static List<Constructor<?>> getConstructors(Class<?> targetClass)
    • getMethods

      public static Map<String, List<Method>> getMethods(Class<?> targetClass, boolean staticMethods)
    • getAllMethods

      @Deprecated public static Map<String, List<Method>> getAllMethods(Class<?> targetClass, boolean staticMethods)
      Deprecated.
    • getMethods

      public static List<Method> getMethods(Class<?> targetClass, String name, boolean staticMethods)
    • getAllMethods

      @Deprecated public static List<Method> getAllMethods(Class<?> targetClass, String name, boolean staticMethods)
      Deprecated.
    • getFields

      public static Map<String,Field> getFields(Class<?> targetClass)
    • getField

      public static Field getField(Class<?> inClass, String name)
    • getFieldValue

      @Deprecated public static Object getFieldValue(OgnlContext context, Object target, String propertyName) throws NoSuchFieldException
      Deprecated.
      Don't use this method as it doesn't check member access rights via MemberAccess interface
      Parameters:
      context - the current execution context.
      target - the object to invoke the property name get on.
      propertyName - the name of the property to be set for target.
      Returns:
      the result invoking field retrieval of propertyName for target.
      Throws:
      NoSuchFieldException - if the field does not exist.
    • getFieldValue

      public static Object getFieldValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) throws NoSuchFieldException
      Throws:
      NoSuchFieldException
    • setFieldValue

      @Deprecated public static boolean setFieldValue(OgnlContext context, Object target, String propertyName, Object value) throws OgnlException
      Deprecated.
      Don't use this method as it doesn't check member access rights via MemberAccess interface
      Throws:
      OgnlException
    • setFieldValue

      public static boolean setFieldValue(OgnlContext context, Object target, String propertyName, Object value, boolean checkAccessAndExistence) throws OgnlException
      Throws:
      OgnlException
    • isFieldAccessible

      public static boolean isFieldAccessible(OgnlContext context, Object target, Class<?> inClass, String propertyName)
    • isFieldAccessible

      public static boolean isFieldAccessible(OgnlContext context, Object target, Field field, String propertyName)
    • hasField

      public static boolean hasField(OgnlContext context, Object target, Class<?> inClass, String propertyName)
    • getStaticField

      public static Object getStaticField(OgnlContext context, String className, String fieldName) throws OgnlException
      Method name is getStaticField(), but actually behaves more like "getStaticFieldValue()".

      Typical usage: Returns the value (not the actual Field) for the given (static) fieldName. May return the Enum constant value for the given fieldName when className is an Enum. May return a Class instance when the given fieldName is "class".

      Parameters:
      context - The current ognl context
      className - The name of the class which contains the field
      fieldName - The name of the field whose value should be returned
      Returns:
      The value of the (static) fieldName
      Throws:
      OgnlException - for lots of different reasons.
    • getDeclaredMethods

      public static List<Method> getDeclaredMethods(Class<?> targetClass, String propertyName, boolean findSets)
    • isMethodCallable

      public static boolean isMethodCallable(Method m)
      Convenience used to check if a method is a synthetic method so as to avoid calling un-callable methods. These methods are not considered callable by OGNL in almost all circumstances.

      This method considers any synthetic method (even bridge methods) as being un-callable. Even though synthetic and bridge methods can technically be called, by default OGNL excludes them from consideration.

      Synthetic methods should be excluded in general, since calling such methods could introduce unanticipated risks.

      Parameters:
      m - The method to check.
      Returns:
      True if the method should be callable (non-synthetic), false otherwise.
    • getGetMethod

      public static Method getGetMethod(Class<?> targetClass, String propertyName)
      cache get methods
      Parameters:
      targetClass - the Class to invoke the property name "getter" retrieval on.
      propertyName - the name of the property for which a "getter" is sought.
      Returns:
      the Method representing a "getter" for propertyName of targetClass.
    • isMethodAccessible

      public static boolean isMethodAccessible(OgnlContext context, Object target, Method method, String propertyName)
    • hasGetMethod

      public static boolean hasGetMethod(OgnlContext context, Object target, Class<?> targetClass, String propertyName)
    • getSetMethod

      public static Method getSetMethod(OgnlContext context, Class<?> targetClass, String propertyName)
      cache set methods method
      Parameters:
      context - the current execution context.
      targetClass - the Class to invoke the property name "setter" retrieval on.
      propertyName - the name of the property for which a "setter" is sought.
      Returns:
      the Method representing a "setter" for propertyName of targetClass.
    • hasSetMethod

      public static boolean hasSetMethod(OgnlContext context, Object target, Class<?> targetClass, String propertyName)
    • hasGetProperty

      public static boolean hasGetProperty(OgnlContext context, Object target, Object oname) throws IntrospectionException
      Throws:
      IntrospectionException
    • hasSetProperty

      public static boolean hasSetProperty(OgnlContext context, Object target, Object oname) throws IntrospectionException
      Throws:
      IntrospectionException
    • getPropertyDescriptors

      public static Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?> targetClass)
      This method returns the property descriptors for the given class as a Map.
      Parameters:
      targetClass - The class to get the descriptors for.
      Returns:
      Map of property descriptors for class.
    • getPropertyDescriptor

      public static PropertyDescriptor getPropertyDescriptor(Class<?> targetClass, String propertyName) throws OgnlException
      This method returns a PropertyDescriptor for the given class and property name using a Map lookup (using getPropertyDescriptorsMap()).
      Parameters:
      targetClass - the class to get the descriptors for.
      propertyName - the property name of targetClass for which a Descriptor is requested.
      Returns:
      the PropertyDescriptor for propertyName of targetClass.
      Throws:
      OgnlException - On general errors.
    • getPropertyDescriptorsArray

      public static PropertyDescriptor[] getPropertyDescriptorsArray(Class<?> targetClass)
    • getPropertyDescriptorFromArray

      public static PropertyDescriptor getPropertyDescriptorFromArray(Class<?> targetClass, String name)
      Gets the property descriptor with the given name for the target class given.
      Parameters:
      targetClass - Class for which property descriptor is desired
      name - Name of property
      Returns:
      PropertyDescriptor of the named property or null if the class has no property with the given name
    • setMethodAccessor

      public static void setMethodAccessor(Class<?> clazz, MethodAccessor accessor)
    • getMethodAccessor

      public static MethodAccessor getMethodAccessor(Class<?> clazz) throws OgnlException
      Throws:
      OgnlException
    • setPropertyAccessor

      public static void setPropertyAccessor(Class<?> clazz, PropertyAccessor accessor)
    • getPropertyAccessor

      public static PropertyAccessor getPropertyAccessor(Class<?> clazz) throws OgnlException
      Throws:
      OgnlException
    • getElementsAccessor

      public static ElementsAccessor getElementsAccessor(Class<?> clazz) throws OgnlException
      Throws:
      OgnlException
    • setElementsAccessor

      public static void setElementsAccessor(Class<?> clazz, ElementsAccessor accessor)
    • getNullHandler

      public static NullHandler getNullHandler(Class<?> clazz) throws OgnlException
      Throws:
      OgnlException
    • setNullHandler

      public static void setNullHandler(Class<?> clazz, NullHandler handler)
    • getProperty

      public static Object getProperty(OgnlContext context, Object source, Object name) throws OgnlException
      Throws:
      OgnlException
    • setProperty

      public static void setProperty(OgnlContext context, Object target, Object name, Object value) throws OgnlException
      Throws:
      OgnlException
    • getIndexedPropertyType

      public static int getIndexedPropertyType(Class<?> sourceClass, String name) throws OgnlException
      Determines the index property type, if any. Returns INDEXED_PROPERTY_NONE if the property is not index-accessible as determined by OGNL or JavaBeans. If it is indexable then this will return whether it is a JavaBeans indexed property, conforming to the indexed property patterns (returns INDEXED_PROPERTY_INT) or if it conforms to the OGNL arbitrary object indexable (returns INDEXED_PROPERTY_OBJECT).
      Parameters:
      sourceClass - the Class to invoke indexed property type retrieval on.
      name - the name of the property for which an indexed property type is sought.
      Returns:
      the indexed property type (int) for the property name of sourceClass. Returns INDEXED_PROPERTY_NONE if name is not an indexed property.
      Throws:
      OgnlException - for lots of different reasons.
    • getIndexedProperty

      public static Object getIndexedProperty(OgnlContext context, Object source, String name, Object index) throws OgnlException
      Throws:
      OgnlException
    • setIndexedProperty

      public static void setIndexedProperty(OgnlContext context, Object source, String name, Object index, Object value) throws OgnlException
      Throws:
      OgnlException
    • getEvaluationPool

      public static EvaluationPool getEvaluationPool()
    • setClassCacheInspector

      public static void setClassCacheInspector(ClassCacheInspector inspector)
      Registers the specified ClassCacheInspector with all class reflection based internal caches. This may have a significant performance impact so be careful using this in production scenarios.
      Parameters:
      inspector - The inspector instance that will be registered with all internal cache instances.
    • getMethod

      public static Method getMethod(OgnlContext context, Class<?> target, String name, Node[] children, boolean includeStatic) throws Exception
      Throws:
      Exception
    • getReadMethod

      public static Method getReadMethod(Class<?> target, String name)
      Finds the best possible match for a method on the specified target class with a matching name.

      The name matched will also try different combinations like is + name, has + name, get + name, etc..

      Parameters:
      target - The class to find a matching method against.
      name - The name of the method.
      Returns:
      The most likely matching Method, or null if none could be found.
    • getReadMethod

      public static Method getReadMethod(Class<?> target, String name, Class<?>[] argClasses)
    • getWriteMethod

      public static Method getWriteMethod(Class<?> target, String name)
    • getWriteMethod

      public static Method getWriteMethod(Class<?> target, String name, Class<?>[] argClasses)
    • getProperty

      public static PropertyDescriptor getProperty(Class<?> target, String name)
    • isBoolean

      public static boolean isBoolean(String expression)
    • shouldConvertNumericTypes

      public static boolean shouldConvertNumericTypes(OgnlContext context)
      Compares the OgnlContext.getCurrentType() and OgnlContext.getPreviousType() class types on the stack to determine if a numeric expression should force object conversion.

      Normally used in conjunction with the forceConversion parameter of getChildSource(OgnlContext, Object, Node).

      Parameters:
      context - The current context.
      Returns:
      True, if the class types on the stack wouldn't be comparable in a pure numeric expression such as o1 >= o2.
    • getChildSource

      public static String getChildSource(OgnlContext context, Object target, Node child)
      Attempts to get the java source string represented by the specific child expression via the JavaSource.toGetSourceString(OgnlContext, Object) interface method.
      Parameters:
      context - The ognl context to pass to the child.
      target - The current object target to use.
      child - The child expression.
      Returns:
      The result of calling JavaSource.toGetSourceString(OgnlContext, Object) plus additional enclosures of OgnlOps.convertValue(Object, Class, boolean) for conversions.
    • getUseJDK9PlusAccessHandlerValue

      public static boolean getUseJDK9PlusAccessHandlerValue()
      Returns the value of the flag indicating whether the JDK9+ access handler has been been requested (it can then be used if the Major Java Version number is 9+).

      Note: Value is controlled by a Java option flag USE_JDK9PLUS_ACCESS_HANDLER.

      Returns:
      true if a request to use the JDK9+ access handler is requested, false otherwise (always use pre-JDK9 handler).
      Since:
      3.1.25
    • getUseStricterInvocationValue

      public static boolean getUseStricterInvocationValue()
      Returns the value of the flag indicating whether "stricter" invocation is in effect or not.

      Note: Value is controlled by a Java option flag USE_STRICTER_INVOCATION.

      Returns:
      true if stricter invocation is in effect, false otherwise.
      Since:
      3.1.25
    • getDisableOgnlSecurityManagerOnInitValue

      @Deprecated public static boolean getDisableOgnlSecurityManagerOnInitValue()
      Deprecated.
      will be removed in 3.5.x
      Returns the value of the flag indicating whether the OGNL SecurityManager was disabled on initialization or not.

      Note: Value is controlled by a Java option flag OGNL_SECURITY_MANAGER using the value OGNL_SM_FORCE_DISABLE_ON_INIT.

      Returns:
      true if OGNL SecurityManager was disabled on initialization, false otherwise.
      Since:
      3.1.25
    • usingJDK9PlusAccessHandler

      public static boolean usingJDK9PlusAccessHandler()
      Returns an indication as to whether the current state indicates the JDK9+ (9 and later) access handler is being used / should be used. This is based on a combination of the detected Major Java Version and the Java option flag USE_JDK9PLUS_ACCESS_HANDLER.
      Returns:
      true if the JDK9 and later access handler is being used / should be used, false otherwise.
      Since:
      3.1.25
    • getUseFirstMatchGetSetLookupValue

      public static boolean getUseFirstMatchGetSetLookupValue()
      Returns the value of the flag indicating whether the old "first match" lookup for getters/setters is in effect or not.

      Note: Value is controlled by a Java option flag USE_FIRSTMATCH_GETSET_LOOKUP.

      Returns:
      true if the old "first match" lookup is in effect, false otherwise.
      Since:
      3.1.25