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

Check null for the packages field of ClassLoader #252

Open
wants to merge 1 commit into
base: master
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
11 changes: 8 additions & 3 deletions src/main/java/zone/rong/loliasm/core/LoliTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import zone.rong.loliasm.LoliLogger;
import zone.rong.loliasm.patches.*;

import java.lang.reflect.Field;
import java.util.*;
import java.util.function.Function;

Expand Down Expand Up @@ -527,9 +528,13 @@ private byte[] removePackageField(byte[] bytes) {
// Canonicalize default ClassLoader packages strings first so any more of the same package strings uses those instances instead.

try {
Map<String, Package> packages = (Map<String, Package>) LoliReflector.getField(ClassLoader.class, "packages").get(Launch.classLoader);
Set<String> packageStrings = packages.keySet();
packageStrings.forEach(LoliStringPool::canonicalize);
Field packagesField = LoliReflector.getField(ClassLoader.class, "packages");
// Packages field is reflection blacklisted on newer Java versions
if (packagesField != null) {
Map<String, Package> packages = (Map<String, Package>) LoliReflector.getField(ClassLoader.class, "packages").get(Launch.classLoader);
Set<String> packageStrings = packages.keySet();
packageStrings.forEach(LoliStringPool::canonicalize);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Expand Down