Class OgnlRuntime
- Handles majority of reflection logic / caching.
- Utility methods for casting strings / various numeric types used by
OgnlExpressionCompiler. - Core runtime configuration point for setting/using global
TypeConverter/OgnlExpressionCompiler/NullHandlerinstances / etc..
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTells whether the given array of objects is compatible with the given array of classes---that is, whether the given array of objects can be passed as arguments to a method or constructor whose parameter types are the given array of classes.private static final classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AccessibleObjectHandlerprivate static OgnlExpressionCompilerExpression compiler used byOgnl.compileExpression(OgnlContext, Object, String)calls.private static final booleanDeprecated.will be removed in 3.5.x(package private) static final EvaluationPoolprivate static final booleanprivate static final intprivate static final booleanHold environment flag state associated with USE_FIRSTMATCH_GETSET_LOOKUP.private static final booleanHold environment flag state associated with USE_JDK9PLUS_ACESS_HANDLER.private static final booleanHold environment flag state associated with USE_STRICTER_INVOCATION.private static final Methodprivate static final Method(package private) static final OgnlCache(package private) static final OgnlRuntime.ClassPropertyMethodCache(package private) static final OgnlRuntime.ClassPropertyMethodCacheprivate static final Class<?>[]static final StringJava beans standard get method prefix.private static final intPrefix padding for hexadecimal numbers to HEX_LENGTH.static intJavaBeans IndexedPropertystatic intNot an indexed propertystatic intOGNL ObjectIndexedPropertystatic final StringJava beans standardis<Foo>boolean getter prefix.static final OgnlRuntime.ArgsCompatbilityReportstatic final Object[]static final ObjectToken returned by TypeConverter for no conversion possiblestatic final ObjectConstant expression used to indicate that a given method / property couldn't be found during reflection operations.private static final StringReturned bygetUniqueDescriptor()when the object isnull.static final StringConstant string representation of null string.private static final NumericCastsConstant strings for casting different primitive types.private static final NumericDefaultsprivate static final NumericLiteralsNumeric primitive literal string expressions.private static final NumericValuesConstant strings for getting the primitive value of different native types on the genericNumberobject interface.(package private) static final StringDeprecated.will removed in 3.5.x(package private) static final Stringprivate static final PrimitiveDefaultsprivate static final PrimitiveTypesprivate static final PrimitiveWrapperClassesUsed to provide primitive type equivalent conversions into and out of native / object types.(package private) static SecurityManagerDeprecated.will be removed in 3.5.xstatic final StringJava beans standard set method prefix.private static final MethodPrivate references for use in blocking direct invocation by invokeMethod().private static final Method(package private) static final StringAllow users to revert to the old "first match" lookup for getters/setters by OGNL using the JVM options: -Dognl.UseFirstMatchGetSetLookup=true -Dognl.UseFirstMatchGetSetLookup=false(package private) static final StringControl usage of JDK9+ access handler using the JVM option: -Dognl.UseJDK9PlusAccessHandler=true -Dognl.UseJDK9PlusAccessHandler=false(package private) static final StringControl usage of "stricter" invocation processing by invokeMethod() using the JVM options: -Dognl.UseStricterInvocation=true -Dognl.UseStricterInvocation=false -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Method_getGetMethod(Class<?> targetClass, String propertyName) Returns a qualifying get (getter) method, if one is available for the given targetClass and propertyName.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.areArgsCompatible(Class<?>[] args, Class<?>[] classes, Method m) static booleanareArgsCompatible(Object[] args, Class<?>[] classes) static ObjectcallAppropriateMethod(OgnlContext context, Object source, Object target, String methodName, String propertyName, List<Method> methods, Object[] args) static ObjectcallConstructor(OgnlContext context, String className, Object[] args) static ObjectcallMethod(OgnlContext context, Object target, String methodName, Object[] args) Invokes the specified method against the target object.static ObjectcallMethod(OgnlContext context, Object target, String methodName, String propertyName, Object[] args) Deprecated.UsecallMethod(OgnlContext, Object, String, Object[])instead.static ObjectcallStaticMethod(OgnlContext context, String className, String methodName, Object[] args) static <T> Class<T> classForName(OgnlContext context, String className) static voidClears some additional caches used by OgnlRuntime.static voidClears 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.static voidcompileExpression(OgnlContext context, Node expression, Object root) (package private) static intDetect the (reported) Major Java version running OGNL.private static OgnlRuntime.MatchingMethodstatic Class<?>[]findParameterTypes(Class<?> type, Method method) getAllMethods(Class<?> targetClass, boolean staticMethods) Deprecated.getAllMethods(Class<?> targetClass, String name, boolean staticMethods) Deprecated.static MethodgetAppropriateMethod(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.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.static Class<?>[]getArgClasses(Object[] args) static StringReturns the base name (the class name without the package name prepended) of the object given.static StringgetChildSource(OgnlContext context, Object target, Node child) Attempts to get the java source string represented by the specific child expression via theJavaSource.toGetSourceString(OgnlContext, Object)interface method.static StringgetClassBaseName(Class<?> c) Returns the base name (the class name without the package name prepended) of the class given.static StringgetClassName(Class<?> c, boolean fullyQualified) static StringgetClassName(Object o, boolean fullyQualified) static StringgetClassPackageName(Class<?> c) Returns the package name of the class given.static OgnlExpressionCompilerstatic List<Constructor<?>> getConstructors(Class<?> targetClass) static Constructor<?> getConvertedConstructorAndArgs(OgnlContext context, Object target, List<Constructor<?>> constructors, Object[] args, Object[] newArgs) static MethodgetConvertedMethodAndArgs(OgnlContext context, Object target, String propertyName, List<Method> methods, Object[] args, Object[] newArgs) static ObjectgetConvertedType(OgnlContext context, Object target, Member member, String propertyName, Object value, Class<?> type) static booleangetConvertedTypes(OgnlContext context, Object target, Member member, String propertyName, Class<?>[] parameterTypes, Object[] args, Object[] newArgs) getDeclaredMethods(Class<?> targetClass, String propertyName, boolean findSets) static booleanDeprecated.will be removed in 3.5.xstatic ElementsAccessorgetElementsAccessor(Class<?> clazz) static EvaluationPoolstatic Fieldstatic ObjectgetFieldValue(OgnlContext context, Object target, String propertyName) Deprecated.static ObjectgetFieldValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) static MethodgetGetMethod(Class<?> targetClass, String propertyName) cache get methodsstatic ObjectgetIndexedProperty(OgnlContext context, Object source, String name, Object index) static intgetIndexedPropertyType(Class<?> sourceClass, String name) Determines the index property type, if any.static intGet the Major Java Version detected by OGNL.static MethodgetMethod(OgnlContext context, Class<?> target, String name, Node[] children, boolean includeStatic) static MethodAccessorgetMethodAccessor(Class<?> clazz) getMethods(Class<?> targetClass, boolean staticMethods) getMethods(Class<?> targetClass, String name, boolean staticMethods) static ObjectgetMethodValue(OgnlContext context, Object target, String propertyName) Deprecated.static ObjectgetMethodValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) 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.static StringgetModifierString(int modifiers) static NullHandlergetNullHandler(Class<?> clazz) static StringgetNumericCast(Class<? extends Number> type) static ObjectgetNumericDefaultValue(Class<?> forClass) static StringgetNumericLiteral(Class<?> type) static StringgetNumericValueGetter(Class<?> type) static StringReturns the package name of the object's class.static Class<?>[]getParameterTypes(Constructor<?> constructor) Returns the parameter types of the given method.static Class<?>[]getParameterTypes(Method method) Returns the parameter types of the given method.static PermissiongetPermission(Method method) Deprecated.since 3.4.6, forRemoval = truestatic StringgetPointerString(int num) Returns a "pointer" string in the usual format for these things - 0x<hex digits>.static StringReturns a "pointer" string in the usual format for these things - 0x<hex digits> for the object given.static ObjectgetPrimitiveDefaultValue(Class<?> forClass) static Class<?> getPrimitiveWrapperClass(Class<?> primitiveClass) static PropertyDescriptorgetProperty(Class<?> target, String name) static ObjectgetProperty(OgnlContext context, Object source, Object name) static PropertyAccessorgetPropertyAccessor(Class<?> clazz) static PropertyDescriptorgetPropertyDescriptor(Class<?> targetClass, String propertyName) This method returns a PropertyDescriptor for the given class and property name using a Map lookup (using getPropertyDescriptorsMap()).static PropertyDescriptorgetPropertyDescriptorFromArray(Class<?> targetClass, String name) Gets the property descriptor with the given name for the target class given.static Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?> targetClass) This method returns the property descriptors for the given class as a Map.static PropertyDescriptor[]getPropertyDescriptorsArray(Class<?> targetClass) static MethodgetReadMethod(Class<?> target, String name) Finds the best possible match for a method on the specified target class with a matching name.static MethodgetReadMethod(Class<?> target, String name, Class<?>[] argClasses) static SecurityManagerDeprecated.will be removed in 3.5.xstatic MethodgetSetMethod(OgnlContext context, Class<?> targetClass, String propertyName) cache set methods methodstatic ObjectgetStaticField(OgnlContext context, String className, String fieldName) Method name is getStaticField(), but actually behaves more like "getStaticFieldValue()".static Class<?> Gets the "target" class of an object for looking up accessors that are registered on the target.static StringgetUniqueDescriptor(Object object) Returns a unique descriptor string that includes the object's class' base name and a unique integer identifier.static StringgetUniqueDescriptor(Object object, boolean fullyQualified) Returns a unique descriptor string that includes the object's class and a unique integer identifier.static booleanReturns the value of the flag indicating whether the old "first match" lookup for getters/setters is in effect or not.static booleanReturns 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+).static booleanReturns the value of the flag indicating whether "stricter" invocation is in effect or not.static MethodgetWriteMethod(Class<?> target, String name) static MethodgetWriteMethod(Class<?> target, String name, Class<?>[] argClasses) static booleanhasField(OgnlContext context, Object target, Class<?> inClass, String propertyName) static booleanhasGetMethod(OgnlContext context, Object target, Class<?> targetClass, String propertyName) static booleanhasGetProperty(OgnlContext context, Object target, Object oname) static booleanhasSetMethod(OgnlContext context, Object target, Class<?> targetClass, String propertyName) static booleanhasSetProperty(OgnlContext context, Object target, Object oname) static ObjectinvokeMethod(Object target, Method method, Object[] argsArray) private static ObjectinvokeMethodInsideSandbox(Object target, Method method, Object[] argsArray) private static booleanisAccessible(OgnlContext context, Object target, Member member, String propertyName) Returns true if the given member is accessible or can be made accessible by this object.static booleanprivate static booleanisDefaultMethod(Method method) Backport of java.lang.reflect.Method#isDefault()static booleanisFieldAccessible(OgnlContext context, Object target, Class<?> inClass, String propertyName) static booleanisFieldAccessible(OgnlContext context, Object target, Field field, String propertyName) static booleanisInstance(OgnlContext context, Object value, String className) static booleanDeprecated.since 3.4.6, forRemoval = truestatic booleanisMethodAccessible(OgnlContext context, Object target, Method method, String propertyName) static booleanConvenience used to check if a method is a synthetic method so as to avoid calling un-callable methods.(package private) static booleanConvenience used to check if a method is either a non-synthetic method or a bridge method.static booleanisMoreSpecific(Class<?>[] classes1, Class<?>[] classes2) Tells whether the first array of classes is more specific than the second.private static booleanDetermine if the provided Method is a non-Default public Interface method.static booleanisTypeCompatible(Class<?> parameterClass, Class<?> methodArgumentClass, int index, OgnlRuntime.ArgsCompatbilityReport report) static booleanisTypeCompatible(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.(package private) static intparseMajorJavaVersion(String versionString) Parse a Java version string to determine the Major Java version.static voidsetClassCacheInspector(ClassCacheInspector inspector) Registers the specifiedClassCacheInspectorwith all class reflection based internal caches.static voidsetCompiler(OgnlExpressionCompiler compiler) static voidsetElementsAccessor(Class<?> clazz, ElementsAccessor accessor) static booleansetFieldValue(OgnlContext context, Object target, String propertyName, Object value) Deprecated.static booleansetFieldValue(OgnlContext context, Object target, String propertyName, Object value, boolean checkAccessAndExistence) static voidsetIndexedProperty(OgnlContext context, Object source, String name, Object index, Object value) static voidsetMethodAccessor(Class<?> clazz, MethodAccessor accessor) static booleansetMethodValue(OgnlContext context, Object target, String propertyName, Object value) Deprecated.static booleansetMethodValue(OgnlContext context, Object target, String propertyName, Object value, boolean checkAccessAndExistence) static voidsetNullHandler(Class<?> clazz, NullHandler handler) static voidsetProperty(OgnlContext context, Object target, Object name, Object value) static voidsetPropertyAccessor(Class<?> clazz, PropertyAccessor accessor) static voidDeprecated.will be removed in 3.5.xstatic booleanshouldConvertNumericTypes(OgnlContext context) Compares theOgnlContext.getCurrentType()andOgnlContext.getPreviousType()class types on the stack to determine if a numeric expression should force object conversion.static booleanReturns an indication as to whether the current state indicates the JDK9+ (9 and later) access handler is being used / should be used.
-
Field Details
-
NotFound
Constant expression used to indicate that a given method / property couldn't be found during reflection operations. -
NoArguments
-
NoConversionPossible
Token returned by TypeConverter for no conversion possible -
INDEXED_PROPERTY_NONE
public static int INDEXED_PROPERTY_NONENot an indexed property -
INDEXED_PROPERTY_INT
public static int INDEXED_PROPERTY_INTJavaBeans IndexedProperty -
INDEXED_PROPERTY_OBJECT
public static int INDEXED_PROPERTY_OBJECTOGNL ObjectIndexedProperty -
NULL_STRING
Constant string representation of null string. -
SET_PREFIX
Java beans standard set method prefix.- See Also:
-
GET_PREFIX
Java beans standard get method prefix.- See Also:
-
IS_PREFIX
Java beans standardis<Foo>boolean getter prefix.- See Also:
-
HEX_PADDING
Prefix padding for hexadecimal numbers to HEX_LENGTH. -
HEX_LENGTH
private static final int HEX_LENGTH- See Also:
-
NULL_OBJECT_STRING
Returned bygetUniqueDescriptor()when the object isnull.- See Also:
-
USE_JDK9PLUS_ACCESS_HANDLER
Control usage of JDK9+ access handler using the JVM option: -Dognl.UseJDK9PlusAccessHandler=true -Dognl.UseJDK9PlusAccessHandler=falseNote: 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
Control usage of "stricter" invocation processing by invokeMethod() using the JVM options: -Dognl.UseStricterInvocation=true -Dognl.UseStricterInvocation=falseNote: 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 _useJDK9PlusAccessHandlerHold environment flag state associated with USE_JDK9PLUS_ACESS_HANDLER. Default: false (if not set) -
_useStricterInvocation
private static final boolean _useStricterInvocationHold 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
-
SYS_CONSOLE_REF
Private references for use in blocking direct invocation by invokeMethod(). -
SYS_EXIT_REF
-
AO_SETACCESSIBLE_REF
-
AO_SETACCESSIBLE_ARR_REF
-
OGNL_SECURITY_MANAGER
Deprecated.will removed in 3.5.xControl 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
- See Also:
-
_disableOgnlSecurityManagerOnInit
Deprecated.will be removed in 3.5.xHold environment flag state associated with OGNL_SECURITY_MANAGER. SeeOGNL_SECURITY_MANAGERfor more details. Default: false (if not set). -
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=falseNote: 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 _useFirstMatchGetSetLookupHold environment flag state associated with USE_FIRSTMATCH_GETSET_LOOKUP. Default: false (if not set) -
cache
-
primitiveTypes
-
primitiveDefaults
-
securityManager
Deprecated.will be removed in 3.5.x -
_evaluationPool
-
_methodAccessCache
-
_methodPermCache
-
cacheSetMethod
-
cacheGetMethod
-
_compiler
Expression compiler used byOgnl.compileExpression(OgnlContext, Object, String)calls. -
primitiveWrapperClasses
Used to provide primitive type equivalent conversions into and out of native / object types. -
numericCasts
Constant strings for casting different primitive types. -
numericValues
Constant strings for getting the primitive value of different native types on the genericNumberobject interface. (or the less generic BigDecimal/BigInteger types) -
numericLiterals
Numeric primitive literal string expressions. -
numericDefaults
-
EMPTY_CLASS_ARRAY
-
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 existingclearCache()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.since 3.4.6, forRemoval = trueCheck 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
-
getPrimitiveWrapperClass
-
getNumericCast
-
getNumericLiteral
-
setCompiler
-
getCompiler
-
compileExpression
public static void compileExpression(OgnlContext context, Node expression, Object root) throws Exception - Throws:
Exception
-
getTargetClass
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
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
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
-
getClassName
-
getPackageName
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
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
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
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
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
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
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
Finds the appropriate parameter types for the givenMethodandClassinstance 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
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.will be removed in 3.5.xGets the SecurityManager that OGNL uses to determine permissions for invoking methods.- Returns:
- SecurityManager for OGNL
-
setSecurityManager
Deprecated.will be removed in 3.5.xSets the SecurityManager that OGNL uses to determine permissions for invoking methods.- Parameters:
value- SecurityManager to set
-
getPermission
Deprecated.since 3.4.6, forRemoval = truePermission 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 -
invokeMethodInsideSandbox
private static Object invokeMethodInsideSandbox(Object target, Method method, Object[] argsArray) throws InvocationTargetException, IllegalAccessException -
getArgClass
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
-
isTypeCompatible
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
-
areArgsCompatible
public static OgnlRuntime.ArgsCompatbilityReport areArgsCompatible(Class<?>[] args, Class<?>[] classes, Method m) -
isMoreSpecific
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
-
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
-
getNumericDefaultValue
-
getConvertedType
-
getConvertedTypes
-
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
-
findBestMethod
-
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 Deprecated.UsecallMethod(OgnlContext, Object, String, Object[])instead.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 viaMemberAccessinterface- 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 usingIntrospector.
-
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 viaMemberAccessinterface- 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
-
getMethods
-
isDefaultMethod
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
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
-
getAllMethods
@Deprecated public static List<Method> getAllMethods(Class<?> targetClass, String name, boolean staticMethods) Deprecated. -
getFields
-
getField
-
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 viaMemberAccessinterface- 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 viaMemberAccessinterface- 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 theEnumconstant value for the given fieldName when className is anEnum. May return aClassinstance when the given fieldName is "class".- Parameters:
context- The current ognl contextclassName- The name of the class which contains the fieldfieldName- 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
-
isMethodCallable
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
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
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
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
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
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
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
-
getPropertyDescriptorFromArray
Gets the property descriptor with the given name for the target class given.- Parameters:
targetClass- Class for which property descriptor is desiredname- Name of property- Returns:
- PropertyDescriptor of the named property or null if the class has no property with the given name
-
setMethodAccessor
-
getMethodAccessor
- Throws:
OgnlException
-
setPropertyAccessor
-
getPropertyAccessor
- Throws:
OgnlException
-
getElementsAccessor
- Throws:
OgnlException
-
setElementsAccessor
-
getNullHandler
- Throws:
OgnlException
-
setNullHandler
-
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
Determines the index property type, if any. ReturnsINDEXED_PROPERTY_NONEif 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 (returnsINDEXED_PROPERTY_INT) or if it conforms to the OGNL arbitrary object indexable (returnsINDEXED_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_NONEif 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
-
setClassCacheInspector
Registers the specifiedClassCacheInspectorwith 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
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
-
getWriteMethod
-
getWriteMethod
-
getProperty
-
isBoolean
-
shouldConvertNumericTypes
Compares theOgnlContext.getCurrentType()andOgnlContext.getPreviousType()class types on the stack to determine if a numeric expression should force object conversion.Normally used in conjunction with the
forceConversionparameter ofgetChildSource(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
Attempts to get the java source string represented by the specific child expression via theJavaSource.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 ofOgnlOps.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
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.will be removed in 3.5.xReturns 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_MANAGERusing the valueOGNL_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 flagUSE_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.
-