Skip to content

Commit 9b440d1

Browse files
committed
Filter module-info from loading.
1 parent 7f6eb4f commit 9b440d1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/ByteBuddy.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -801,24 +801,27 @@ public DynamicType.Builder<?> makeRecord() {
801801
/**
802802
* Creates a new module with the given name.
803803
*
804-
* @param name The name of the module.
804+
* @param name The name of the module.
805+
* @param modifierContributor The modifier contributors for the module.
805806
* @return A builder for a new module.
806807
*/
807-
public DynamicType.Builder.ModuleDefinition<?> makeModule(String name) {
808-
return makeModule(name, false);
808+
public DynamicType.Builder.ModuleDefinition<?> makeModule(String name,
809+
ModifierContributor.ForModule... modifierContributor) {
810+
return makeModule(name, Arrays.asList(modifierContributor));
809811
}
810812

811813
/**
812814
* Creates a new module with the given name.
813815
*
814-
* @param name The name of the module.
815-
* @param open {@code true} if the module is to be opened.
816+
* @param name The name of the module.
817+
* @param modifierContributors The modifier contributors for the module.
816818
* @return A builder for a new module.
817819
*/
818-
public DynamicType.Builder.ModuleDefinition<?> makeModule(String name, boolean open) {
820+
public DynamicType.Builder.ModuleDefinition<?> makeModule(String name,
821+
Collection<? extends ModifierContributor.ForModule> modifierContributors) {
819822
return subclass(Object.class)
820823
.name(ModuleDescription.MODULE_CLASS_NAME)
821-
.module(name, open ? Opcodes.ACC_OPEN : ModifierContributor.EMPTY_MASK);
824+
.module(name, modifierContributors);
822825
}
823826

824827
/**

byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.bytebuddy.ClassFileVersion;
2020
import net.bytebuddy.build.AccessControllerPlugin;
2121
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
22+
import net.bytebuddy.description.module.ModuleDescription;
2223
import net.bytebuddy.description.type.TypeDescription;
2324
import net.bytebuddy.utility.GraalImageCode;
2425
import net.bytebuddy.utility.JavaModule;
@@ -366,6 +367,9 @@ public static Map<TypeDescription, Class<?>> load(@MaybeNull ClassLoader classLo
366367
ClassFilePostProcessor.NoOp.INSTANCE);
367368
Map<TypeDescription, Class<?>> result = new LinkedHashMap<TypeDescription, Class<?>>();
368369
for (TypeDescription typeDescription : types.keySet()) {
370+
if (typeDescription.getName().equals(ModuleDescription.MODULE_CLASS_NAME)) {
371+
continue;
372+
}
369373
try {
370374
Class<?> type = Class.forName(typeDescription.getName(), false, classLoader);
371375
if (!GraalImageCode.getCurrent().isNativeImageExecution() && forbidExisting && type.getClassLoader() != classLoader) {
@@ -1292,6 +1296,9 @@ public static Map<TypeDescription, Class<?>> load(@MaybeNull ClassLoader classLo
12921296
ClassFilePostProcessor.NoOp.INSTANCE);
12931297
Map<TypeDescription, Class<?>> result = new LinkedHashMap<TypeDescription, Class<?>>();
12941298
for (TypeDescription typeDescription : types.keySet()) {
1299+
if (typeDescription.getName().equals(ModuleDescription.MODULE_CLASS_NAME)) {
1300+
continue;
1301+
}
12951302
try {
12961303
Class<?> type = Class.forName(typeDescription.getName(), false, classLoader);
12971304
if (!GraalImageCode.getCurrent().isNativeImageExecution() && forbidExisting && type.getClassLoader() != classLoader) {

0 commit comments

Comments
 (0)