Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace '/'s in class names with '.'s instead of throwing an exception. #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,32 @@ class MixinAgentClassLoader extends ClassLoader {
private static final ILogger logger = MixinService.getService().getLogger("mixin.agent");

/**
* Mapping of mixin mixin classes to their fake classes
* Mapping of mixin classes to their fake classes
*/
private Map<Class<?>, byte[]> mixins = new HashMap<Class<?>, byte[]>();
private final Map<Class<?>, byte[]> mixins = new HashMap<Class<?>, byte[]>();

/**
* Mapping that keep track of bytecode for classes that are targeted by
* mixins
*/
private Map<String, byte[]> targets = new HashMap<String, byte[]>();
private final Map<String, byte[]> targets = new HashMap<String, byte[]>();

/**
* Add a fake mixin class
*
* @param name Name of the fake class
*/
void addMixinClass(String name) {
// Ensure that classes with '/'s in their names are replaced with '.'s,
// this can happen when hot swapping mixins in fabric, for more details see:
// https://github.com/FabricMC/fabric/issues/1934 and https://github.com/FabricMC/Mixin/issues/76.
name = name.replace('/', '.');

MixinAgentClassLoader.logger.debug("Mixin class {} added to class loader", name);
try {
byte[] bytes = this.materialise(name);
Class<?> clazz = this.defineClass(name, bytes, 0, bytes.length);
// apparently the class needs to be instantiated at least once
// Apparently the class needs to be instantiated at least once
// to be including in list returned by allClasses() method in jdi api
clazz.getDeclaredConstructor().newInstance();
this.mixins.put(clazz, bytes);
Expand Down