{"record":{"id":"a04d9b5aceebe268","repo":"skylot/jadx","slug":"package-is-null-for-not-inner-class","errorCode":null,"errorMessage":"Package is null for not inner class","messagePattern":"Package is null for not inner class","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java","lineNumber":239,"sourceCode":"\t\t}\n\t\treturn aliasPkg.replace('.', File.separatorChar) + File.separatorChar + fileName;\n\t}\n\n\tpublic String getFullName() {\n\t\treturn fullName;\n\t}\n\n\tpublic String getShortName() {\n\t\treturn name;\n\t}\n\n\t@NotNull\n\tpublic String getPackage() {\n\t\tif (parentClass != null) {\n\t\t\treturn parentClass.getPackage();\n\t\t}\n\t\tif (pkg == null) {\n\t\t\tthrow new JadxRuntimeException(\"Package is null for not inner class\");\n\t\t}\n\t\treturn pkg;\n\t}\n\n\tpublic boolean isDefaultPackage() {\n\t\treturn getPackage().isEmpty();\n\t}\n\n\tpublic String getRawName() {\n\t\treturn type.getObject();\n\t}\n\n\tpublic String getAliasNameWithoutPackage() {\n\t\tif (parentClass == null) {\n\t\t\treturn getAliasShortName();\n\t\t}\n\t\treturn parentClass.getAliasNameWithoutPackage() + '.' + getAliasShortName();\n\t}","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java#L221-L257","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corrupt class descriptors; ClassInfo objects built outside the normal factory (fromName/fromType); partial copies; bugs in alias logic that null out pkg.","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."],"exampleFix":"// before\nif (pkg == null) {\n    throw new JadxRuntimeException(\"Package is null for not inner class\");\n}\nreturn pkg;\n\n// after (treat null as default package)\nif (pkg == null) {\n    LOG.warn(\"Null package on top-level class {}\", this);\n    return \"\";\n}\nreturn pkg;","handlingStrategy":"validation","validationCode":"// Ensure pkg is non-null at construction for top-level classes\nString pkg = computedPkg != null ? computedPkg : \"\";","typeGuard":"static boolean hasValidPackage(ClassInfo ci) {\n    return ci.isInner() || ci.getPackageField() != null;\n}","tryCatchPattern":"String pkg;\ntry {\n    pkg = classInfo.getPackage();\n} catch (JadxRuntimeException e) {\n    pkg = \"\"; // default package fallback\n}","preventionTips":["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."],"tags":["classinfo","package","invariant","null-check"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}