{"record":{"id":"161a61d5af98eaf2","repo":"MuntashirAkon/AppManager","slug":"unknown-density-densityname","errorCode":null,"errorMessage":"Unknown density {densityName}","messagePattern":"Unknown density (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/apk/ApkUtils.java","lineNumber":320,"sourceCode":"        OsEnvironment.UserEnvironment userEnvironment = OsEnvironment.getUserEnvironment(userId);\n        Path[] extDirs = userEnvironment.getExternalDirs();\n        Path writableExtDir = null;\n        for (Path extDir : extDirs) {\n            if (extDir.canWrite() || Objects.requireNonNull(extDir.getFilePath()).startsWith(\"/storage/emulated\")) {\n                writableExtDir = extDir;\n                break;\n            }\n        }\n        if (writableExtDir == null) {\n            throw new FileNotFoundException(\"Couldn't find any writable Obb dir\");\n        }\n        return writableExtDir;\n    }\n\n    public static int getDensityFromName(@Nullable String densityName) {\n        Integer density = StaticDataset.DENSITY_NAME_TO_DENSITY.get(densityName);\n        if (density == null) {\n            throw new IllegalArgumentException(\"Unknown density \" + densityName);\n        }\n        return density;\n    }\n\n    @NonNull\n    private static ByteBuffer getAndroidManifestFromApk(\n            @NonNull List<CentralDirectoryRecord> cdRecords, @NonNull DataSource lhfSection)\n            throws IOException, ApkFormatException, ZipFormatException {\n        CentralDirectoryRecord androidManifestCdRecord = findCdRecord(cdRecords, MANIFEST_FILE);\n        if (androidManifestCdRecord == null) {\n            throw new ApkFormatException(\"Missing \" + MANIFEST_FILE);\n        }\n        return ByteBuffer.wrap(LocalFileRecord.getUncompressedData(\n                lhfSection, androidManifestCdRecord, lhfSection.size()));\n    }\n\n    @Nullable\n    private static CentralDirectoryRecord findCdRecord(","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/apk/ApkUtils.java#L302-L338","documentation":"getDensityFromName looks up a density bucket name (e.g. \"mdpi\", \"xhdpi\") in StaticDataset.DENSITY_NAME_TO_DENSITY and throws IllegalArgumentException when the name is not a known Android density qualifier. It enforces that only recognized AAPT density names are converted to numeric density values.","triggerScenarios":"Calling ApkUtils.getDensityFromName with a name absent from StaticDataset.DENSITY_NAME_TO_DENSITY — e.g. misspelled qualifiers (\"hdpiar\"), unknown/new density buckets, or a null/empty string extracted from a split APK name.","commonSituations":"Parsing config strings from APK split filenames with an unexpected format, handling vendor-specific density labels, or passing user input / locale-mixed strings instead of canonical Android density names.","solutions":["Normalize the input to a canonical Android density name (ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, nodpi, tvdpi) before calling.","Pre-validate with StaticDataset.DENSITY_NAME_TO_DENSITY.containsKey(name) and use a default density when absent.","Wrap in try-catch for IllegalArgumentException and fall back to DisplayMetrics.DENSITY_DEFAULT.","If parsing from file names, fix the extraction regex so only the density segment is passed."],"exampleFix":"// before\nint density = ApkUtils.getDensityFromName(densityName);\n// after\nint density = StaticDataset.DENSITY_NAME_TO_DENSITY.containsKey(densityName)\n        ? ApkUtils.getDensityFromName(densityName)\n        : DisplayMetrics.DENSITY_DEFAULT;","handlingStrategy":"validation","validationCode":"if (densityName == null || !StaticDataset.DENSITY_NAME_TO_DENSITY.containsKey(densityName)) {\n    densityName = \"nodpi\"; // or skip\n}","typeGuard":"boolean isValidDensity(String name) {\n    return name != null && StaticDataset.DENSITY_NAME_TO_DENSITY.containsKey(name);\n}","tryCatchPattern":"try {\n    int density = ApkUtils.getDensityFromName(name);\n} catch (IllegalArgumentException e) {\n    int density = DisplayMetrics.DENSITY_DEFAULT;\n}","preventionTips":["Use StaticDataset's known keys as the single source of truth for valid names.","Extract density names from APK split names with a strict regex and lowercase them.","Default unknown densities instead of failing hard when the value is only advisory.","Add a unit test covering every density constant your app can encounter."],"tags":["android","validation","argument","density"],"backgroundTag":"invalid-enum-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}