Skip to content

Commit

Permalink
Auto module export with reentrant protection
Browse files Browse the repository at this point in the history
Signed-off-by: JermaineHua <crazyhzm@apache.org>
  • Loading branch information
CrazyHZM committed Sep 23, 2024
1 parent 6d844ab commit 3663c21
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,29 @@
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* @author huazhongming
* @since 4.4.0
*/
public class ModuleUtil {

Check warning on line 32 in sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java#L32

Added line #L32 was not covered by tests

private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(ModuleUtil.class);
private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(ModuleUtil.class);

private static final MethodHandle implAddOpensToAllUnnamed;

private static final MethodHandle implAddOpens;

private static final MethodHandle implAddExportsToAllUnnamed;

private static final MethodHandle implAddExports;

private static final Map<String, Module> nameToModules;

private static final AtomicBoolean isExported = new AtomicBoolean(false);

static {
implAddOpensToAllUnnamed = createModuleMethodHandle("implAddOpensToAllUnnamed",
String.class);
Expand All @@ -54,7 +61,7 @@ public class ModuleUtil {
*/
public static void exportAllJDKModulePackageToAll() {
try {
if (nameToModules != null) {
if (isExported.compareAndSet(false,true) && nameToModules != null) {
nameToModules.forEach((name, module) -> module.getPackages().forEach(pkgName -> {
if (isJDKModulePackage(pkgName)) {
addOpensToAll(module, pkgName);
Expand All @@ -76,8 +83,7 @@ private static boolean isJDKModulePackage(String modulePackageName) {
*/
public static void exportAllModulePackageToAll() {
try {
Map<String, Module> nameToModules = getNameToModule();
if (nameToModules != null) {
if (isExported.compareAndSet(false,true) && nameToModules != null) {
nameToModules.forEach((name, module) -> module.getPackages().forEach(pkgName -> {
addOpensToAll(module, pkgName);
addExportsToAll(module, pkgName);
Expand Down

0 comments on commit 3663c21

Please sign in to comment.