Java Code Examples for sun.reflect.Reflection#quickCheckMemberAccess()

The following examples show how to use sun.reflect.Reflection#quickCheckMemberAccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Method.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Invokes the underlying method represented by this {@code Method}
 * object, on the specified object with the specified parameters.
 * Individual parameters are automatically unwrapped to match
 * primitive formal parameters, and both primitive and reference
 * parameters are subject to method invocation conversions as
 * necessary.
 *
 * <p>If the underlying method is static, then the specified {@code obj}
 * argument is ignored. It may be null.
 *
 * <p>If the number of formal parameters required by the underlying method is
 * 0, the supplied {@code args} array may be of length 0 or null.
 *
 * <p>If the underlying method is an instance method, it is invoked
 * using dynamic method lookup as documented in The Java Language
 * Specification, Second Edition, section 15.12.4.4; in particular,
 * overriding based on the runtime type of the target object will occur.
 *
 * <p>If the underlying method is static, the class that declared
 * the method is initialized if it has not already been initialized.
 *
 * <p>If the method completes normally, the value it returns is
 * returned to the caller of invoke; if the value has a primitive
 * type, it is first appropriately wrapped in an object. However,
 * if the value has the type of an array of a primitive type, the
 * elements of the array are <i>not</i> wrapped in objects; in
 * other words, an array of primitive type is returned.  If the
 * underlying method return type is void, the invocation returns
 * null.
 *
 * @param obj  the object the underlying method is invoked from
 * @param args the arguments used for the method call
 * @return the result of dispatching the method represented by
 * this object on {@code obj} with parameters
 * {@code args}
 *
 * @exception IllegalAccessException    if this {@code Method} object
 *              is enforcing Java language access control and the underlying
 *              method is inaccessible.
 * @exception IllegalArgumentException  if the method is an
 *              instance method and the specified object argument
 *              is not an instance of the class or interface
 *              declaring the underlying method (or of a subclass
 *              or implementor thereof); if the number of actual
 *              and formal parameters differ; if an unwrapping
 *              conversion for primitive arguments fails; or if,
 *              after possible unwrapping, a parameter value
 *              cannot be converted to the corresponding formal
 *              parameter type by a method invocation conversion.
 * @exception InvocationTargetException if the underlying method
 *              throws an exception.
 * @exception NullPointerException      if the specified object is null
 *              and the method is an instance method.
 * @exception ExceptionInInitializerError if the initialization
 * provoked by this method fails.
 */
@CallerSensitive
public Object invoke(Object obj, Object... args)
    throws IllegalAccessException, IllegalArgumentException,
       InvocationTargetException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    MethodAccessor ma = methodAccessor;             // read volatile
    if (ma == null) {
        ma = acquireMethodAccessor();
    }
    return ma.invoke(obj, args);
}
 
Example 2
Source File: Method.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invokes the underlying method represented by this {@code Method}
 * object, on the specified object with the specified parameters.
 * Individual parameters are automatically unwrapped to match
 * primitive formal parameters, and both primitive and reference
 * parameters are subject to method invocation conversions as
 * necessary.
 *
 * <p>If the underlying method is static, then the specified {@code obj}
 * argument is ignored. It may be null.
 *
 * <p>If the number of formal parameters required by the underlying method is
 * 0, the supplied {@code args} array may be of length 0 or null.
 *
 * <p>If the underlying method is an instance method, it is invoked
 * using dynamic method lookup as documented in The Java Language
 * Specification, Second Edition, section 15.12.4.4; in particular,
 * overriding based on the runtime type of the target object will occur.
 *
 * <p>If the underlying method is static, the class that declared
 * the method is initialized if it has not already been initialized.
 *
 * <p>If the method completes normally, the value it returns is
 * returned to the caller of invoke; if the value has a primitive
 * type, it is first appropriately wrapped in an object. However,
 * if the value has the type of an array of a primitive type, the
 * elements of the array are <i>not</i> wrapped in objects; in
 * other words, an array of primitive type is returned.  If the
 * underlying method return type is void, the invocation returns
 * null.
 *
 * @param obj  the object the underlying method is invoked from
 * @param args the arguments used for the method call
 * @return the result of dispatching the method represented by
 * this object on {@code obj} with parameters
 * {@code args}
 *
 * @exception IllegalAccessException    if this {@code Method} object
 *              is enforcing Java language access control and the underlying
 *              method is inaccessible.
 * @exception IllegalArgumentException  if the method is an
 *              instance method and the specified object argument
 *              is not an instance of the class or interface
 *              declaring the underlying method (or of a subclass
 *              or implementor thereof); if the number of actual
 *              and formal parameters differ; if an unwrapping
 *              conversion for primitive arguments fails; or if,
 *              after possible unwrapping, a parameter value
 *              cannot be converted to the corresponding formal
 *              parameter type by a method invocation conversion.
 * @exception InvocationTargetException if the underlying method
 *              throws an exception.
 * @exception NullPointerException      if the specified object is null
 *              and the method is an instance method.
 * @exception ExceptionInInitializerError if the initialization
 * provoked by this method fails.
 */
@CallerSensitive
public Object invoke(Object obj, Object... args)
    throws IllegalAccessException, IllegalArgumentException,
       InvocationTargetException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    MethodAccessor ma = methodAccessor;             // read volatile
    if (ma == null) {
        ma = acquireMethodAccessor();
    }
    return ma.invoke(obj, args);
}
 
Example 3
Source File: Field.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code int} or of another primitive type convertible to
 * type {@code int} via a widening conversion.
 *
 * @param obj the object to extract the {@code int} value
 * from
 * @return the value of the field converted to type {@code int}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code int} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public int getInt(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getInt(obj);
}
 
Example 4
Source File: Field.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the value of the field represented by this {@code Field}, on
 * the specified object. The value is automatically wrapped in an
 * object if it has a primitive type.
 *
 * <p>The underlying field's value is obtained as follows:
 *
 * <p>If the underlying field is a static field, the {@code obj} argument
 * is ignored; it may be null.
 *
 * <p>Otherwise, the underlying field is an instance field.  If the
 * specified {@code obj} argument is null, the method throws a
 * {@code NullPointerException}. If the specified object is not an
 * instance of the class or interface declaring the underlying
 * field, the method throws an {@code IllegalArgumentException}.
 *
 * <p>If this {@code Field} object is enforcing Java language access control, and
 * the underlying field is inaccessible, the method throws an
 * {@code IllegalAccessException}.
 * If the underlying field is static, the class that declared the
 * field is initialized if it has not already been initialized.
 *
 * <p>Otherwise, the value is retrieved from the underlying instance
 * or static field.  If the field has a primitive type, the value
 * is wrapped in an object before being returned, otherwise it is
 * returned as is.
 *
 * <p>If the field is hidden in the type of {@code obj},
 * the field's value is obtained according to the preceding rules.
 *
 * @param obj object from which the represented field's value is
 * to be extracted
 * @return the value of the represented field in object
 * {@code obj}; primitive values are wrapped in an appropriate
 * object before being returned
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof).
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 */
@CallerSensitive
public Object get(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).get(obj);
}
 
Example 5
Source File: Field.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the value of a field as a {@code char} on the specified object.
 * This method is equivalent to
 * {@code set(obj, cObj)},
 * where {@code cObj} is a {@code Character} object and
 * {@code cObj.charValue() == c}.
 *
 * @param obj the object whose field should be modified
 * @param c   the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#set
 */
@CallerSensitive
public void setChar(Object obj, char c)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).setChar(obj, c);
}
 
Example 6
Source File: Field.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code long} or of another primitive type convertible to
 * type {@code long} via a widening conversion.
 *
 * @param obj the object to extract the {@code long} value
 * from
 * @return the value of the field converted to type {@code long}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code long} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public long getLong(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getLong(obj);
}
 
Example 7
Source File: Field.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance {@code boolean} field.
 *
 * @param obj the object to extract the {@code boolean} value
 * from
 * @return the value of the {@code boolean} field
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code boolean} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public boolean getBoolean(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getBoolean(obj);
}
 
Example 8
Source File: Field.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code long} or of another primitive type convertible to
 * type {@code long} via a widening conversion.
 *
 * @param obj the object to extract the {@code long} value
 * from
 * @return the value of the field converted to type {@code long}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code long} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public long getLong(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getLong(obj);
}
 
Example 9
Source File: Field.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance {@code byte} field.
 *
 * @param obj the object to extract the {@code byte} value
 * from
 * @return the value of the {@code byte} field
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code byte} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public byte getByte(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getByte(obj);
}
 
Example 10
Source File: Field.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the value of a field as a {@code long} on the specified object.
 * This method is equivalent to
 * {@code set(obj, lObj)},
 * where {@code lObj} is a {@code Long} object and
 * {@code lObj.longValue() == l}.
 *
 * @param obj the object whose field should be modified
 * @param l   the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#set
 */
@CallerSensitive
public void setLong(Object obj, long l)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            checkAccess(Reflection.getCallerClass(), clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).setLong(obj, l);
}
 
Example 11
Source File: Field.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the value of the field represented by this {@code Field}, on
 * the specified object. The value is automatically wrapped in an
 * object if it has a primitive type.
 *
 * <p>The underlying field's value is obtained as follows:
 *
 * <p>If the underlying field is a static field, the {@code obj} argument
 * is ignored; it may be null.
 *
 * <p>Otherwise, the underlying field is an instance field.  If the
 * specified {@code obj} argument is null, the method throws a
 * {@code NullPointerException}. If the specified object is not an
 * instance of the class or interface declaring the underlying
 * field, the method throws an {@code IllegalArgumentException}.
 *
 * <p>If this {@code Field} object is enforcing Java language access control, and
 * the underlying field is inaccessible, the method throws an
 * {@code IllegalAccessException}.
 * If the underlying field is static, the class that declared the
 * field is initialized if it has not already been initialized.
 *
 * <p>Otherwise, the value is retrieved from the underlying instance
 * or static field.  If the field has a primitive type, the value
 * is wrapped in an object before being returned, otherwise it is
 * returned as is.
 *
 * <p>If the field is hidden in the type of {@code obj},
 * the field's value is obtained according to the preceding rules.
 *
 * @param obj object from which the represented field's value is
 * to be extracted
 * @return the value of the represented field in object
 * {@code obj}; primitive values are wrapped in an appropriate
 * object before being returned
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof).
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 */
@CallerSensitive
public Object get(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).get(obj);
}
 
Example 12
Source File: Field.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the value of a field as a {@code float} on the specified object.
 * This method is equivalent to
 * {@code set(obj, fObj)},
 * where {@code fObj} is a {@code Float} object and
 * {@code fObj.floatValue() == f}.
 *
 * @param obj the object whose field should be modified
 * @param f   the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#set
 */
@CallerSensitive
public void setFloat(Object obj, float f)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).setFloat(obj, f);
}
 
Example 13
Source File: Field.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code int} or of another primitive type convertible to
 * type {@code int} via a widening conversion.
 *
 * @param obj the object to extract the {@code int} value
 * from
 * @return the value of the field converted to type {@code int}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code int} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public int getInt(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            checkAccess(Reflection.getCallerClass(), clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getInt(obj);
}
 
Example 14
Source File: Field.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code float} or of another primitive type convertible to
 * type {@code float} via a widening conversion.
 *
 * @param obj the object to extract the {@code float} value
 * from
 * @return the value of the field converted to type {@code float}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code float} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see Field#get
 */
@CallerSensitive
public float getFloat(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getFloat(obj);
}
 
Example 15
Source File: Field.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code double} or of another primitive type convertible to
 * type {@code double} via a widening conversion.
 *
 * @param obj the object to extract the {@code double} value
 * from
 * @return the value of the field converted to type {@code double}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code double} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public double getDouble(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getDouble(obj);
}
 
Example 16
Source File: Field.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code long} or of another primitive type convertible to
 * type {@code long} via a widening conversion.
 *
 * @param obj the object to extract the {@code long} value
 * from
 * @return the value of the field converted to type {@code long}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code long} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public long getLong(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getLong(obj);
}
 
Example 17
Source File: Field.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the value of a field as a {@code boolean} on the specified object.
 * This method is equivalent to
 * {@code set(obj, zObj)},
 * where {@code zObj} is a {@code Boolean} object and
 * {@code zObj.booleanValue() == z}.
 *
 * @param obj the object whose field should be modified
 * @param z   the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#set
 */
@CallerSensitive
public void setBoolean(Object obj, boolean z)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).setBoolean(obj, z);
}
 
Example 18
Source File: Field.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the value of a static or instance field of type
 * {@code char} or of another primitive type convertible to
 * type {@code char} via a widening conversion.
 *
 * @param obj the object to extract the {@code char} value
 * from
 * @return the value of the field converted to type {@code char}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code char} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see Field#get
 */
@CallerSensitive
public char getChar(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getChar(obj);
}
 
Example 19
Source File: Field.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the value of the field represented by this {@code Field}, on
 * the specified object. The value is automatically wrapped in an
 * object if it has a primitive type.
 *
 * <p>The underlying field's value is obtained as follows:
 *
 * <p>If the underlying field is a static field, the {@code obj} argument
 * is ignored; it may be null.
 *
 * <p>Otherwise, the underlying field is an instance field.  If the
 * specified {@code obj} argument is null, the method throws a
 * {@code NullPointerException}. If the specified object is not an
 * instance of the class or interface declaring the underlying
 * field, the method throws an {@code IllegalArgumentException}.
 *
 * <p>If this {@code Field} object is enforcing Java language access control, and
 * the underlying field is inaccessible, the method throws an
 * {@code IllegalAccessException}.
 * If the underlying field is static, the class that declared the
 * field is initialized if it has not already been initialized.
 *
 * <p>Otherwise, the value is retrieved from the underlying instance
 * or static field.  If the field has a primitive type, the value
 * is wrapped in an object before being returned, otherwise it is
 * returned as is.
 *
 * <p>If the field is hidden in the type of {@code obj},
 * the field's value is obtained according to the preceding rules.
 *
 * @param obj object from which the represented field's value is
 * to be extracted
 * @return the value of the represented field in object
 * {@code obj}; primitive values are wrapped in an appropriate
 * object before being returned
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof).
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 */
@CallerSensitive
public Object get(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).get(obj);
}
 
Example 20
Source File: Field.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the value of the field represented by this {@code Field}, on
 * the specified object. The value is automatically wrapped in an
 * object if it has a primitive type.
 *
 * <p>The underlying field's value is obtained as follows:
 *
 * <p>If the underlying field is a static field, the {@code obj} argument
 * is ignored; it may be null.
 *
 * <p>Otherwise, the underlying field is an instance field.  If the
 * specified {@code obj} argument is null, the method throws a
 * {@code NullPointerException}. If the specified object is not an
 * instance of the class or interface declaring the underlying
 * field, the method throws an {@code IllegalArgumentException}.
 *
 * <p>If this {@code Field} object is enforcing Java language access control, and
 * the underlying field is inaccessible, the method throws an
 * {@code IllegalAccessException}.
 * If the underlying field is static, the class that declared the
 * field is initialized if it has not already been initialized.
 *
 * <p>Otherwise, the value is retrieved from the underlying instance
 * or static field.  If the field has a primitive type, the value
 * is wrapped in an object before being returned, otherwise it is
 * returned as is.
 *
 * <p>If the field is hidden in the type of {@code obj},
 * the field's value is obtained according to the preceding rules.
 *
 * @param obj object from which the represented field's value is
 * to be extracted
 * @return the value of the represented field in object
 * {@code obj}; primitive values are wrapped in an appropriate
 * object before being returned
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof).
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 */
@CallerSensitive
public Object get(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).get(obj);
}