Skip to content

Fix npe in CompatHandler#getPackageName #775

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

Open
wants to merge 2 commits into
base: MC_1.12
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 @@ -113,11 +113,19 @@ private static Map<String, String> getPackageToModId() {
}

private static String getPackageName(Class<?> clazz) {
String canonicalName = clazz.getCanonicalName();
int dot = canonicalName.lastIndexOf('.'); //cannot occur anywhere in the class name itself
String name = clazz.getCanonicalName();
if(name == null) {
Class<?> enclosingClass = clazz.getEnclosingClass();
if (enclosingClass != null) {
return getPackageName(enclosingClass);
} else {
name = clazz.getName();
}
}
int dot = name.lastIndexOf('.'); //cannot occur anywhere in the class name itself
return dot < 0
? "" //default package
: canonicalName.substring(0, dot);
: name.substring(0, dot);
}

public static Set<String> getModsForStacktrace(StackTraceElement[] stacktrace) {
Expand Down