< prev index next >

src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java

Print this page
rev 51057 : 8206865: RMI activation tests fail with InvalidClassException
Reviewed-by: darcy, alanb


 434      * checking for a serializable class and its superclasses
 435      * up to, but not including, the first non-serializable
 436      * superclass. This also implies that the superclass is
 437      * always non-null, because a serializable class must be a
 438      * class (not an interface) and Object is not serializable.
 439      *
 440      * @param cl the class from which access is checked
 441      * @return whether the superclass has a constructor accessible from cl
 442      */
 443     private boolean superHasAccessibleConstructor(Class<?> cl) {
 444         Class<?> superCl = cl.getSuperclass();
 445         assert Serializable.class.isAssignableFrom(cl);
 446         assert superCl != null;
 447         if (packageEquals(cl, superCl)) {
 448             // accessible if any non-private constructor is found
 449             for (Constructor<?> ctor : superCl.getDeclaredConstructors()) {
 450                 if ((ctor.getModifiers() & Modifier.PRIVATE) == 0) {
 451                     return true;
 452                 }
 453             }



 454             return false;
 455         } else {
 456             // sanity check to ensure the parent is protected or public
 457             if ((superCl.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) == 0) {
 458                 return false;
 459             }
 460             // accessible if any constructor is protected or public
 461             for (Constructor<?> ctor : superCl.getDeclaredConstructors()) {
 462                 if ((ctor.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) != 0) {
 463                     return true;
 464                 }
 465             }
 466             return false;
 467         }
 468     }
 469 
 470     /**
 471      * Returns a constructor that allocates an instance of cl and that then initializes
 472      * the instance by calling the no-arg constructor of its first non-serializable
 473      * superclass. This is specified in the Serialization Specification, section 3.1,




 434      * checking for a serializable class and its superclasses
 435      * up to, but not including, the first non-serializable
 436      * superclass. This also implies that the superclass is
 437      * always non-null, because a serializable class must be a
 438      * class (not an interface) and Object is not serializable.
 439      *
 440      * @param cl the class from which access is checked
 441      * @return whether the superclass has a constructor accessible from cl
 442      */
 443     private boolean superHasAccessibleConstructor(Class<?> cl) {
 444         Class<?> superCl = cl.getSuperclass();
 445         assert Serializable.class.isAssignableFrom(cl);
 446         assert superCl != null;
 447         if (packageEquals(cl, superCl)) {
 448             // accessible if any non-private constructor is found
 449             for (Constructor<?> ctor : superCl.getDeclaredConstructors()) {
 450                 if ((ctor.getModifiers() & Modifier.PRIVATE) == 0) {
 451                     return true;
 452                 }
 453             }
 454             if (Reflection.areNestMates(cl, superCl)) {
 455                 return true;
 456             }
 457             return false;
 458         } else {
 459             // sanity check to ensure the parent is protected or public
 460             if ((superCl.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) == 0) {
 461                 return false;
 462             }
 463             // accessible if any constructor is protected or public
 464             for (Constructor<?> ctor : superCl.getDeclaredConstructors()) {
 465                 if ((ctor.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) != 0) {
 466                     return true;
 467                 }
 468             }
 469             return false;
 470         }
 471     }
 472 
 473     /**
 474      * Returns a constructor that allocates an instance of cl and that then initializes
 475      * the instance by calling the no-arg constructor of its first non-serializable
 476      * superclass. This is specified in the Serialization Specification, section 3.1,


< prev index next >