< prev index next >

src/java.base/share/classes/sun/invoke/util/VerifyAccess.java

Print this page
rev 50983 : 8207027: Lookup.accessClass fails for an array type in the same package when assertions are enabled
Reviewed-by:


 316         return true;
 317     }
 318 
 319     /**
 320      * Tests if two classes are in the same module.
 321      * @param class1 a class
 322      * @param class2 another class
 323      * @return whether they are in the same module
 324      */
 325     public static boolean isSameModule(Class<?> class1, Class<?> class2) {
 326         return class1.getModule() == class2.getModule();
 327     }
 328 
 329     /**
 330      * Test if two classes have the same class loader and package qualifier.
 331      * @param class1 a class
 332      * @param class2 another class
 333      * @return whether they are in the same package
 334      */
 335     public static boolean isSamePackage(Class<?> class1, Class<?> class2) {
 336         assert(!class1.isArray() && !class2.isArray());
 337         if (class1 == class2)
 338             return true;
 339         if (class1.getClassLoader() != class2.getClassLoader())
 340             return false;
 341         return Objects.equals(class1.getPackageName(), class2.getPackageName());
 342     }
 343 
 344     /**
 345      * Test if two classes are defined as part of the same package member (top-level class).
 346      * If this is true, they can share private access with each other.
 347      * @param class1 a class
 348      * @param class2 another class
 349      * @return whether they are identical or nested together
 350      */
 351     public static boolean isSamePackageMember(Class<?> class1, Class<?> class2) {
 352         if (class1 == class2)
 353             return true;
 354         if (!isSamePackage(class1, class2))
 355             return false;
 356         if (getOutermostEnclosingClass(class1) != getOutermostEnclosingClass(class2))




 316         return true;
 317     }
 318 
 319     /**
 320      * Tests if two classes are in the same module.
 321      * @param class1 a class
 322      * @param class2 another class
 323      * @return whether they are in the same module
 324      */
 325     public static boolean isSameModule(Class<?> class1, Class<?> class2) {
 326         return class1.getModule() == class2.getModule();
 327     }
 328 
 329     /**
 330      * Test if two classes have the same class loader and package qualifier.
 331      * @param class1 a class
 332      * @param class2 another class
 333      * @return whether they are in the same package
 334      */
 335     public static boolean isSamePackage(Class<?> class1, Class<?> class2) {

 336         if (class1 == class2)
 337             return true;
 338         if (class1.getClassLoader() != class2.getClassLoader())
 339             return false;
 340         return Objects.equals(class1.getPackageName(), class2.getPackageName());
 341     }
 342 
 343     /**
 344      * Test if two classes are defined as part of the same package member (top-level class).
 345      * If this is true, they can share private access with each other.
 346      * @param class1 a class
 347      * @param class2 another class
 348      * @return whether they are identical or nested together
 349      */
 350     public static boolean isSamePackageMember(Class<?> class1, Class<?> class2) {
 351         if (class1 == class2)
 352             return true;
 353         if (!isSamePackage(class1, class2))
 354             return false;
 355         if (getOutermostEnclosingClass(class1) != getOutermostEnclosingClass(class2))


< prev index next >