skylot/jadx · error · JadxRuntimeException
Package is null for not inner class
Error message
Package is null for not inner class
What it means
Thrown by ClassInfo.getPackage() when the class is not inner (parentClass == null) but its pkg field is null. A top-level class must have a package string (possibly empty for the default package); a null package on a top-level class is an invariant violation, usually a partially-constructed or corrupted ClassInfo.
Source
Thrown at jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java:239
}
return aliasPkg.replace('.', File.separatorChar) + File.separatorChar + fileName;
}
public String getFullName() {
return fullName;
}
public String getShortName() {
return name;
}
@NotNull
public String getPackage() {
if (parentClass != null) {
return parentClass.getPackage();
}
if (pkg == null) {
throw new JadxRuntimeException("Package is null for not inner class");
}
return pkg;
}
public boolean isDefaultPackage() {
return getPackage().isEmpty();
}
public String getRawName() {
return type.getObject();
}
public String getAliasNameWithoutPackage() {
if (parentClass == null) {
return getAliasShortName();
}
return parentClass.getAliasNameWithoutPackage() + '.' + getAliasShortName();
}View on GitHub (pinned to e738a26571)
Solutions
- Always build ClassInfo via the factory methods (fromName/fromType) which initialise pkg.
- If constructing manually, ensure pkg is set to "" (default package) at minimum, never null.
- Audit code paths that mutate pkg to confirm none can set it to null on a top-level class.
- Defensively, treat null pkg as the default package instead of throwing.
Example fix
// before
if (pkg == null) {
throw new JadxRuntimeException("Package is null for not inner class");
}
return pkg;
// after (treat null as default package)
if (pkg == null) {
LOG.warn("Null package on top-level class {}", this);
return "";
}
return pkg; Defensive patterns
Strategy: validation
Validate before calling
// Ensure pkg is non-null at construction for top-level classes String pkg = computedPkg != null ? computedPkg : "";
Type guard
static boolean hasValidPackage(ClassInfo ci) {
return ci.isInner() || ci.getPackageField() != null;
} Try / catch
String pkg;
try {
pkg = classInfo.getPackage();
} catch (JadxRuntimeException e) {
pkg = ""; // default package fallback
} Prevention
- Always build ClassInfo via factory methods that initialise pkg.
- Never null out pkg on a top-level class.
- Treat null pkg as the default package when reading, rather than letting it throw.
When it happens
Trigger: A top-level ClassInfo constructed without initialising the package; reflection/deserialisation that left pkg null; a ClassInfo built from a malformed class name that yielded no package; mutation paths that set pkg to null.
Common situations: Corrupt class descriptors; ClassInfo objects built outside the normal factory (fromName/fromType); partial copies; bugs in alias logic that null out pkg.
Related errors
- Null class type
- Unexpected key in switch:
- Unexpected arg type in catch block:
- Unknown type in literalToString:
- Unexpected visibility flag:
AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14).
Data as JSON: /api/errors/a04d9b5aceebe268.
Report an issue: GitHub.