151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/* 22c87ad3a45cecf9e344487cad1abfdebe79f2c7cNarayan Kamath * Copyright (C) 2014 The Android Open Source Project 320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it 751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as 851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * published by the Free Software Foundation. Oracle designates this 951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided 1051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code. 1151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 1251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT 1351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that 1651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accompanied this code). 1751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 1851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * You should have received a copy of the GNU General Public License version 1951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation, 2051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any 2451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * questions. 2551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 2651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 2751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipackage java.lang.reflect; 2851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 2951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.lang.annotation.Annotation; 3051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 3151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/** 3251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * The AccessibleObject class is the base class for Field, Method and 3351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Constructor objects. It provides the ability to flag a reflected 3451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * object as suppressing default Java language access control checks 3551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * when it is used. The access checks--for public, default (package) 3651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * access, protected, and private members--are performed when Fields, 3751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Methods or Constructors are used to set or get fields, to invoke 3851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * methods, or to create and initialize new instances of classes, 3951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * respectively. 4051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 4151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>Setting the {@code accessible} flag in a reflected object 4251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * permits sophisticated applications with sufficient privilege, such 4351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * as Java Object Serialization or other persistence mechanisms, to 4451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * manipulate objects in a manner that would normally be prohibited. 4551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 4651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>By default, a reflected object is <em>not</em> accessible. 4751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 4851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see Field 4951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see Method 5051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see Constructor 5151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see ReflectPermission 5251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 5351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.2 5451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 5551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipublic class AccessibleObject implements AnnotatedElement { 5651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 5751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 5851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Convenience method to set the {@code accessible} flag for an 5951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * array of objects with a single security check (for efficiency). 6051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 6151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>First, if there is a security manager, its 6251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code checkPermission} method is called with a 6351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code ReflectPermission("suppressAccessChecks")} permission. 6451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 6551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>A {@code SecurityException} is raised if {@code flag} is 6651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code true} but accessibility of any of the elements of the input 6751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code array} may not be changed (for example, if the element 6851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * object is a {@link Constructor} object for the class {@link 6951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * java.lang.Class}). In the event of such a SecurityException, the 7051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accessibility of objects is set to {@code flag} for array elements 7151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * upto (and excluding) the element for which the exception occurred; the 7251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accessibility of elements beyond (and including) the element for which 7351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the exception occurred is unchanged. 7451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 7551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @param array the array of AccessibleObjects 7651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @param flag the new value for the {@code accessible} flag 7751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * in each object 7851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @throws SecurityException if the request is denied. 7951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see SecurityManager#checkPermission 8051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see java.lang.RuntimePermission 8151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 8251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski public static void setAccessible(AccessibleObject[] array, boolean flag) 8351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski throws SecurityException { 8451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski for (int i = 0; i < array.length; i++) { 8551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski setAccessible0(array[i], flag); 8651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 8751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 8851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 8951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 9051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Set the {@code accessible} flag for this object to 9151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the indicated boolean value. A value of {@code true} indicates that 9251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the reflected object should suppress Java language access 9351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * checking when it is used. A value of {@code false} indicates 9451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * that the reflected object should enforce Java language access checks. 9551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 9651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>First, if there is a security manager, its 9751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code checkPermission} method is called with a 9851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code ReflectPermission("suppressAccessChecks")} permission. 9951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 10051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>A {@code SecurityException} is raised if {@code flag} is 10151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code true} but accessibility of this object may not be changed 10251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * (for example, if this element object is a {@link Constructor} object for 10351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the class {@link java.lang.Class}). 10451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 10551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>A {@code SecurityException} is raised if this object is a {@link 10651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * java.lang.reflect.Constructor} object for the class 10751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code java.lang.Class}, and {@code flag} is true. 10851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 10951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @param flag the new value for the {@code accessible} flag 11051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @throws SecurityException if the request is denied. 11151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see SecurityManager#checkPermission 11251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see java.lang.RuntimePermission 11351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 11451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski public void setAccessible(boolean flag) throws SecurityException { 11551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski setAccessible0(this, flag); 11651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 11751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 11820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller /* Check that you aren't exposing java.lang.Class.<init> or sensitive 11920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller fields in java.lang.Class. */ 12051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski private static void setAccessible0(AccessibleObject obj, boolean flag) 12151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski throws SecurityException 12251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski { 12351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski if (obj instanceof Constructor && flag == true) { 12451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski Constructor<?> c = (Constructor<?>)obj; 1257accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller // Android-changed: Added additional checks below. 126f62ddf18ed81105329c4a4793b1909eac449b871Narayan Kamath Class<?> clazz = c.getDeclaringClass(); 1277accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller if (c.getDeclaringClass() == Class.class) { 12851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski throw new SecurityException("Can not make a java.lang.Class" + 12951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski " constructor accessible"); 130f62ddf18ed81105329c4a4793b1909eac449b871Narayan Kamath } else if (clazz == Method.class) { 131f62ddf18ed81105329c4a4793b1909eac449b871Narayan Kamath throw new SecurityException("Can not make a java.lang.reflect.Method" + 132f62ddf18ed81105329c4a4793b1909eac449b871Narayan Kamath " constructor accessible"); 133f62ddf18ed81105329c4a4793b1909eac449b871Narayan Kamath } else if (clazz == Field.class) { 134f62ddf18ed81105329c4a4793b1909eac449b871Narayan Kamath throw new SecurityException("Can not make a java.lang.reflect.Field" + 135f62ddf18ed81105329c4a4793b1909eac449b871Narayan Kamath " constructor accessible"); 13651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 13751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 13851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski obj.override = flag; 13951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 14051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 14151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 14251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Get the value of the {@code accessible} flag for this object. 14351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 14451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @return the value of the object's {@code accessible} flag 14551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 14651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski public boolean isAccessible() { 14751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski return override; 14851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 14951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 15051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 15151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Constructor: only used by the Java Virtual Machine. 15251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 15351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski protected AccessibleObject() {} 15451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 15551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski // Indicates whether language-level access checks are overridden 15651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski // by this object. Initializes to "false". This field is used by 15751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski // Field, Method, and Constructor. 15851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski // 15951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski // NOTE: for security purposes, this field must not be visible 16051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski // outside this package. 16151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski boolean override; 16251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 16351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 16451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @throws NullPointerException {@inheritDoc} 16551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.5 16651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 16751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 16851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski throw new AssertionError("All subclasses should override this method"); 16951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 17051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 17151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 17220938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * {@inheritDoc} 17320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @throws NullPointerException {@inheritDoc} 17420938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @since 1.5 17520938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller */ 17620938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller @Override 17720938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { 17820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller return AnnotatedElement.super.isAnnotationPresent(annotationClass); 17920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller } 18020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller 18120938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller /** 18220938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @throws NullPointerException {@inheritDoc} 18320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @since 1.8 18420938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller */ 18520938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller @Override 18620938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 18720938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller throw new AssertionError("All subclasses should override this method"); 18820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller } 18920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller 19020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller /** 19151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.5 19251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 19351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski public Annotation[] getAnnotations() { 19451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski return getDeclaredAnnotations(); 19551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 19651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 19751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 19820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @throws NullPointerException {@inheritDoc} 19920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @since 1.8 20020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller */ 20120938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller @Override 20220938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) { 20320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // Only annotations on classes are inherited, for all other 20420938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // objects getDeclaredAnnotation is the same as 20520938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // getAnnotation. 20620938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller return getAnnotation(annotationClass); 20720938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller } 20820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller 20920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller /** 21020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @throws NullPointerException {@inheritDoc} 21120938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @since 1.8 21220938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller */ 21320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller @Override 21420938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) { 21520938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // Only annotations on classes are inherited, for all other 21620938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // objects getDeclaredAnnotationsByType is the same as 21720938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // getAnnotationsByType. 21820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller return getAnnotationsByType(annotationClass); 21920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller } 22020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller 22120938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller /** 22251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.5 22351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 22451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski public Annotation[] getDeclaredAnnotations() { 22551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski throw new AssertionError("All subclasses should override this method"); 22651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski } 22751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski} 228