1441 1442 static { 1443 // Get the modules in the boot layer 1444 Stream<Module> bootLayerModules = Layer.boot().modules().stream(); 1445 1446 // Filter out the modules loaded by the boot or platform loader 1447 PrivilegedAction<Set<Module>> pa = () -> 1448 bootLayerModules.filter(SecurityManager::isBootOrPlatformModule) 1449 .collect(Collectors.toSet()); 1450 Set<Module> modules = AccessController.doPrivileged(pa); 1451 1452 // Filter out the non-exported packages 1453 nonExportedPkgs = modules.stream() 1454 .map(Module::getDescriptor) 1455 .map(SecurityManager::nonExportedPkgs) 1456 .flatMap(Set::stream) 1457 .collect(Collectors.toSet()); 1458 } 1459 1460 /** 1461 * Returns true if the module's loader is the boot or platform loader. 1462 */ 1463 private static boolean isBootOrPlatformModule(Module m) { 1464 return m.getClassLoader() == null || 1465 m.getClassLoader() == ClassLoader.getPlatformClassLoader(); 1466 } 1467 1468 /** 1469 * Returns the non-exported packages of the specified module. 1470 */ 1471 private static Set<String> nonExportedPkgs(ModuleDescriptor md) { 1472 // start with all packages in the module 1473 Set<String> pkgs = new HashSet<>(md.packages()); 1474 1475 // remove the non-qualified exported packages 1476 md.exports().stream() 1477 .filter(p -> !p.isQualified()) 1478 .map(Exports::source) 1479 .forEach(pkgs::remove); 1480 | 1441 1442 static { 1443 // Get the modules in the boot layer 1444 Stream<Module> bootLayerModules = Layer.boot().modules().stream(); 1445 1446 // Filter out the modules loaded by the boot or platform loader 1447 PrivilegedAction<Set<Module>> pa = () -> 1448 bootLayerModules.filter(SecurityManager::isBootOrPlatformModule) 1449 .collect(Collectors.toSet()); 1450 Set<Module> modules = AccessController.doPrivileged(pa); 1451 1452 // Filter out the non-exported packages 1453 nonExportedPkgs = modules.stream() 1454 .map(Module::getDescriptor) 1455 .map(SecurityManager::nonExportedPkgs) 1456 .flatMap(Set::stream) 1457 .collect(Collectors.toSet()); 1458 } 1459 1460 /** 1461 * Called by java.security.Security 1462 */ 1463 static void invalidatePackageAccessCache() { 1464 synchronized (packageAccessLock) { 1465 packageAccessValid = false; 1466 } 1467 synchronized (packageDefinitionLock) { 1468 packageDefinitionValid = false; 1469 } 1470 } 1471 1472 /** 1473 * Returns true if the module's loader is the boot or platform loader. 1474 */ 1475 private static boolean isBootOrPlatformModule(Module m) { 1476 return m.getClassLoader() == null || 1477 m.getClassLoader() == ClassLoader.getPlatformClassLoader(); 1478 } 1479 1480 /** 1481 * Returns the non-exported packages of the specified module. 1482 */ 1483 private static Set<String> nonExportedPkgs(ModuleDescriptor md) { 1484 // start with all packages in the module 1485 Set<String> pkgs = new HashSet<>(md.packages()); 1486 1487 // remove the non-qualified exported packages 1488 md.exports().stream() 1489 .filter(p -> !p.isQualified()) 1490 .map(Exports::source) 1491 .forEach(pkgs::remove); 1492 |