{"record":{"id":"bd7a58e99ddc3f3b","repo":"skylot/jadx","slug":"can-t-change-package-for-inner-class","errorCode":null,"errorMessage":"Can't change package for inner class: {}","messagePattern":"Can't change package for inner class: (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java","lineNumber":87,"sourceCode":"\t\tString aliasPkg = getAliasPkg();\n\t\tif (Objects.equals(name, aliasName) || StringUtils.isEmpty(aliasName)) {\n\t\t\tif (Objects.equals(getPackage(), aliasPkg)) {\n\t\t\t\tnewAlias = null;\n\t\t\t} else {\n\t\t\t\tnewAlias = new ClassAliasInfo(aliasPkg, name);\n\t\t\t}\n\t\t} else {\n\t\t\tnewAlias = new ClassAliasInfo(aliasPkg, aliasName);\n\t\t}\n\t\tif (newAlias != null) {\n\t\t\tfillAliasFullName(newAlias);\n\t\t}\n\t\tthis.alias = newAlias;\n\t}\n\n\tpublic void changePkg(String aliasPkg) {\n\t\tif (isInner()) {\n\t\t\tthrow new JadxRuntimeException(\"Can't change package for inner class: \" + this);\n\t\t}\n\t\tif (!Objects.equals(getAliasPkg(), aliasPkg)) {\n\t\t\tClassAliasInfo newAlias = new ClassAliasInfo(aliasPkg, getAliasShortName());\n\t\t\tfillAliasFullName(newAlias);\n\t\t\tthis.alias = newAlias;\n\t\t}\n\t}\n\n\tpublic void changePkgAndName(String aliasPkg, String aliasShortName) {\n\t\tif (isInner()) {\n\t\t\tthrow new JadxRuntimeException(\"Can't change package for inner class\");\n\t\t}\n\t\tClassAliasInfo newAlias = new ClassAliasInfo(aliasPkg, aliasShortName);\n\t\tfillAliasFullName(newAlias);\n\t\tthis.alias = newAlias;\n\t}\n\n\tprivate void fillAliasFullName(ClassAliasInfo alias) {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java#L69-L105","documentation":"Thrown by ClassInfo.changePkg when attempting to change the package of a class that is an inner class (isInner() true). Package relocation is only valid for top-level classes; an inner class's package is derived from its parent, so changing it directly would break the parent/child relationship.","triggerScenarios":"Calling changePkg(aliasPkg) on a ClassInfo whose parentClass is non-null (an inner/nested class). Common in programmatic rename/batch-move operations that do not distinguish top-level from inner classes.","commonSituations":"Batch deobfuscation/rename scripts that move all classes to a new package; GUI 'move to package' invoked on an inner class; a refactor that reassigns packages recursively including nested classes.","solutions":["Check isInner() before calling changePkg; if true, relocate the enclosing top-level class instead (the inner follows its parent).","For batch moves, iterate only top-level classes (parentClass == null) and let inner classes inherit.","If you genuinely need to repackage an inner class, refactor it to a top-level class first (out of scope for this API).","Catch JadxRuntimeException at the batch boundary to skip inner classes and continue."],"exampleFix":"// before\nclassInfo.changePkg(newPkg); // throws if inner\n\n// after\nif (!classInfo.isInner()) {\n    classInfo.changePkg(newPkg);\n} else {\n    // move the enclosing top-level class; inner follows\n    ClassInfo top = classInfo.getTopParentClass();\n    top.changePkg(newPkg);\n}","handlingStrategy":"validation","validationCode":"if (classInfo.isInner()) {\n    // repackage the enclosing top-level class instead\n    classInfo.getTopParentClass().changePkg(newPkg);\n} else {\n    classInfo.changePkg(newPkg);\n}","typeGuard":"static boolean isRepackageable(ClassInfo ci) {\n    return !ci.isInner();\n}","tryCatchPattern":"try {\n    classInfo.changePkg(newPkg);\n} catch (JadxRuntimeException e) {\n    if (classInfo.isInner()) {\n        classInfo.getTopParentClass().changePkg(newPkg);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Filter to top-level classes before batch repackaging.","Move the enclosing class so inner classes inherit the new package.","Check isInner() before any package-change call."],"tags":["classinfo","inner-class","rename","precondition"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}