public static boolean canAddClassInPackageOf(Class<?> cls){
  final Package beanPackage=cls.getPackage();
  if (beanPackage != null) {
    if (beanPackage.isSealed()) {
      return false;
    }
    String pname=beanPackage.getName();
    if (pname.startsWith("java.") || pname.startsWith("javax.security.")) {
      return false;
    }
  }
  return true;
}

public static boolean canAddClassInPackageOf ( Class < ? > cls ) { final Package beanPackage = cls . getPackage ( ) ; if ( beanPackage != null ) { if ( beanPackage . isSealed ( ) ) { return false ; } String pname = beanPackage . getName ( ) ; if ( pname . startsWith ( "java." ) || pname . startsWith ( "javax.security." ) ) { return false ; } } return true ; }
helper method called to check whether it is acceptable to create a new class in package that given class is part of . this is used to prevent certain class of failures , related to access limitations : for example , we can not add classes in sealed packages , or core java packages ( java . * ) .
