Package ognl

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:
    • HEX_PADDING

      private static final Map<Integer,String> HEX_PADDING
      Prefix padding for hexadecimal numbers to HEX_LENGTH.
    • HEX_LENGTH

      private static final int HEX_LENGTH
      See Also:
    • NULL_OBJECT_STRING

      private static final String NULL_OBJECT_STRING
      Returned by getUniqueDescriptor() when the object is null.
      See Also:
    • USE_JDK9PLUS_ACCESS_HANDLER

      static final String USE_JDK9PLUS_ACCESS_HANDLER
      Control usage of JDK9+ access handler using the JVM option: -Dognl.UseJDK9PlusAccessHandler=true -Dognl.UseJDK9PlusAccessHandler=false

      Note: Set to "true" to allow the new JDK9 and later behaviour, provided a newer JDK9+ is detected. By default the standard pre-JDK9 AccessHandler will be used even when running on JDK9+, so users must "opt-in" in order to enable the alternate JDK9+ AccessHandler. Using the JDK9PlusAccessHandler may avoid / mask JDK9+ warnings of the form: "WARNING: Illegal reflective access by ognl.OgnlRuntime" or provide an alternative when running in environments set with "--illegal-access=deny".

      Note: The default behaviour is to use the standard pre-JDK9 access handler. Using the "false" value has the same effect as omitting the option completely.

      Warning: Users are strongly advised to review their code and confirm they really need the AccessHandler modifying access levels, looking at alternatives to avoid that need.

      See Also:
    • USE_STRICTER_INVOCATION

      static final String USE_STRICTER_INVOCATION
      Control usage of "stricter" invocation processing by invokeMethod() using the JVM options: -Dognl.UseStricterInvocation=true -Dognl.UseStricterInvocation=false

      Note: Using the "true" value has the same effect as omitting the option completely. The default behaviour is to use the "stricter" invocation processing. Using the "false" value reverts to the older "less strict" invocation processing (in the event the "stricter" processing causes issues for existing applications).

      See Also:
    • _useJDK9PlusAccessHandler

      private static final boolean _useJDK9PlusAccessHandler
      Hold environment flag state associated with USE_JDK9PLUS_ACESS_HANDLER. Default: false (if not set)
    • _useStricterInvocation

      private static final boolean _useStricterInvocation
      Hold environment flag state associated with USE_STRICTER_INVOCATION. Default: true (if not set)
    • _majorJavaVersion

      private static final int _majorJavaVersion
    • _jdk9Plus

      private static final boolean _jdk9Plus
    • _accessibleObjectHandler

      private static final AccessibleObjectHandler _accessibleObjectHandler
    • SYS_CONSOLE_REF

      private static final Method SYS_CONSOLE_REF
      Private references for use in blocking direct invocation by invokeMethod().
    • SYS_EXIT_REF

      private static final Method SYS_EXIT_REF
    • AO_SETACCESSIBLE_REF

      private static final Method AO_SETACCESSIBLE_REF
    • AO_SETACCESSIBLE_ARR_REF

      private static final Method AO_SETACCESSIBLE_ARR_REF
    • OGNL_SECURITY_MANAGER

      @Deprecated static final String OGNL_SECURITY_MANAGER
      Deprecated.
      will removed in 3.5.x
      Control usage of the OGNL Security Manager using the JVM option: -Dognl.security.manager=true (or any non-null value other than 'disable')

      Omit '-Dognl.security.manager=' or nullify the property to disable the feature.

      To forcibly disable the feature (only possible at OGNL Library initialization, use the option: -Dognl.security.manager=forceDisableOnInit

      Users that have their own Security Manager implementations and no intention to use the OGNL SecurityManager sandbox may choose to use the 'forceDisableOnInit' flag option for performance reasons (avoiding overhead involving the system property security checks - when that feature will not be used).

      See Also:
    • OGNL_SM_FORCE_DISABLE_ON_INIT

      static final String OGNL_SM_FORCE_DISABLE_ON_INIT
      See Also:
    • _disableOgnlSecurityManagerOnInit

      @Deprecated private static final boolean _disableOgnlSecurityManagerOnInit
      Deprecated.
      will be removed in 3.5.x
      Hold environment flag state associated with OGNL_SECURITY_MANAGER. See OGNL_SECURITY_MANAGER for more details. Default: false (if not set).
    • USE_FIRSTMATCH_GETSET_LOOKUP

      static final String USE_FIRSTMATCH_GETSET_LOOKUP
      Allow users to revert to the old "first match" lookup for getters/setters by OGNL using the JVM options: -Dognl.UseFirstMatchGetSetLookup=true -Dognl.UseFirstMatchGetSetLookup=false

      Note: Using the "false" value has the same effect as omitting the option completely. The default behaviour is to use the "best match" lookup for getters/setters. Using the "true" value reverts to the older "first match" lookup for getters/setters (in the event the "best match" processing causes issues for existing applications).

      See Also:
    • _useFirstMatchGetSetLookup

      private static final boolean _useFirstMatchGetSetLookup
      Hold environment flag state associated with USE_FIRSTMATCH_GETSET_LOOKUP. Default: false (if not set)
    • cache

      static final OgnlCache cache
    • primitiveTypes

      private static final PrimitiveTypes primitiveTypes
    • primitiveDefaults

      private static final PrimitiveDefaults primitiveDefaults
    • securityManager

      @Deprecated static SecurityManager securityManager
      Deprecated.
      will be removed in 3.5.x
    • _evaluationPool

      static final EvaluationPool _evaluationPool
    • _methodAccessCache

      static final Map<Method,Boolean> _methodAccessCache
    • _methodPermCache

      static final Map<Method,Boolean> _methodPermCache
    • cacheSetMethod

      static final OgnlRuntime.ClassPropertyMethodCache cacheSetMethod
    • cacheGetMethod

      static final OgnlRuntime.ClassPropertyMethodCache cacheGetMethod
    • _compiler

      private static OgnlExpressionCompiler _compiler
      Expression compiler used by Ognl.compileExpression(OgnlContext, Object, String) calls.
    • primitiveWrapperClasses

      private static final PrimitiveWrapperClasses primitiveWrapperClasses
      Used to provide primitive type equivalent conversions into and out of native / object types.
    • numericCasts

      private static final NumericCasts numericCasts
      Constant strings for casting different primitive types.
    • numericValues

      private static final NumericValues numericValues
      Constant strings for getting the primitive value of different native types on the generic Number object interface. (or the less generic BigDecimal/BigInteger types)
    • numericLiterals

      private static final NumericLiterals numericLiterals
      Numeric primitive literal string expressions.
    • numericDefaults

      private static final NumericDefaults numericDefaults
    • EMPTY_CLASS_ARRAY

      private static final Class<?>[] EMPTY_CLASS_ARRAY
    • 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
    • invokeMethodInsideSandbox

      private static Object invokeMethodInsideSandbox(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)
    • findBestMethod

      private static OgnlRuntime.MatchingMethod findBestMethod(List<Method> methods, Class<?> typeClass, String name, Class<?>[] argClasses)
    • 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)
    • isDefaultMethod

      private static boolean isDefaultMethod(Method method)
      Backport of java.lang.reflect.Method#isDefault()

      JDK8+ supports Default Methods for interfaces. Default Methods are defined as: public, non-abstract and declared within an interface (must also be non-static).

      Parameters:
      method - The Method to check against the requirements for a Default Method.
      Returns:
      true If the Method qualifies as a Default Method, false otherwise.
    • isNonDefaultPublicInterfaceMethod

      private static boolean isNonDefaultPublicInterfaceMethod(Method method)
      Determine if the provided Method is a non-Default public Interface method.

      Public non-Default Methods are defined as: public, abstract, non-static and declared within an interface.

      Parameters:
      method - The Method to check against the requirements for a non-Default Method.
      Returns:
      true If method qualifies as a non-Default public Interface method, false otherwise.
      Since:
      3.1.25
    • 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.
    • isMethodCallable_BridgeOrNonSynthetic

      static boolean isMethodCallable_BridgeOrNonSynthetic(Method m)
      Convenience used to check if a method is either a non-synthetic method or a bridge method.

      Warning: This method should NOT be used as a direct replacement for isMethodCallable(Method). Almost all OGNL processing assumes the exclusion of synthetic methods in order to process correctly. Only use this method to determine method callability for any OGNL processing after careful consideration.

      This method considers synthetic methods that are not also bridge methods as being un-callable.

      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 or bridge), false otherwise.
      Since:
      3.2.16
    • 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.
    • _getGetMethod

      private static Method _getGetMethod(Class<?> targetClass, String propertyName)
      Returns a qualifying get (getter) method, if one is available for the given targetClass and propertyName.

      Note: From OGNL 3.1.25 onward, this method will attempt to find the first get getter method(s) that match: 1) First get (getter) method, whether public or not. 2) First public get (getter) method, provided the method's declaring class is also public. This may be the same as 1), if 1) is also public and its declaring class is also public. 3) First public non-Default interface get (getter) method, provided the method's declaring class is also public. The order of preference (priority) for the above matches will be 2 (1st public getter), 3 (1st public non-Default interface getter), 1 (1st getter of any kind). This updated methodology should help limit the need to modify method accessibility levels in some circumstances.

      Parameters:
      targetClass - Class to search for a get method (getter).
      propertyName - Name of the property for the get method (getter).
    • 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.
    • _getSetMethod

      private static Method _getSetMethod(OgnlContext context, Class<?> targetClass, String propertyName)
      Returns a qualifying set (setter) method, if one is available for the given targetClass and propertyName.

      Note: From OGNL 3.1.25 onward, this method will attempt to find the first set setter method(s) that match: 1) First set (setter) method, whether public or not. 2) First public set (setter) method, provided the method's declaring class is also public. This may be the same as 1), if 1) is also public and its declaring class is also public. 3) First public non-Default interface set (setter) method, provided the method's declaring class is also public. The order of preference (priority) for the above matches will be 2 (1st public setter), 3 (1st public non-Default interface setter), 1 (1st setter of any kind). This updated methodology should help limit the need to modify method accessibility levels in some circumstances.

      Parameters:
      context - The current execution context.
      targetClass - Class to search for a set method (setter).
      propertyName - Name of the property for the set method (setter).
    • 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.
    • detectMajorJavaVersion

      static int detectMajorJavaVersion()
      Detect the (reported) Major Java version running OGNL.

      Should support naming conventions of pre-JDK9 and JDK9+. See JEP 223: New Version-String Scheme for details.

      Returns:
      Detected Major Java Version, or 5 (minimum supported version for OGNL) if unable to detect.
      Since:
      3.1.25
    • parseMajorJavaVersion

      static int parseMajorJavaVersion(String versionString)
      Parse a Java version string to determine the Major Java version.

      Should support naming conventions of pre-JDK9 and JDK9+. See JEP 223: New Version-String Scheme for details.

      Returns:
      Detected Major Java Version, or 5 (minimum supported version for OGNL) if unable to detect.
      Since:
      3.1.25
    • 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
    • isAccessible

      private static boolean isAccessible(OgnlContext context, Object target, Member member, String propertyName)
      Returns true if the given member is accessible or can be made accessible by this object.
      Parameters:
      context - the current execution context.
      target - the Object to test accessibility for.
      member - the Member to test accessibility for.
      propertyName - the property to test accessibility for.
      Returns:
      true if the target/member/propertyName is accessible in the context, false otherwise.