{"record":{"id":"db129c1e208c004e","repo":"MuntashirAkon/AppManager","slug":"lookupmap-cannot-be-null","errorCode":null,"errorMessage":"lookupMap cannot be null","messagePattern":"lookupMap cannot be null","errorType":"exception","errorClass":"InvalidParameterException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/runner/RunnerUtils.java","lineNumber":162,"sourceCode":"        /**\n         * The length of the longest key in the lookupMap.\n         */\n        private final int mLongest;\n\n        /**\n         * Define the lookup table to be used in translation\n         * <p>\n         * Note that, as of Lang 3.1 (the origin of this code), the key to the lookup\n         * table is converted to a java.lang.String. This is because we need the key\n         * to support hashCode and equals(Object), allowing it to be the key for a\n         * HashMap. See LANG-882.\n         *\n         * @param lookupMap Map&lt;CharSequence, CharSequence&gt; table of translator\n         *                  mappings\n         */\n        public LookupTranslator(final Map<CharSequence, CharSequence> lookupMap) {\n            if (lookupMap == null) {\n                throw new InvalidParameterException(\"lookupMap cannot be null\");\n            }\n            mLookupMap = new HashMap<>();\n            mPrefixSet = new BitSet();\n            int currentShortest = Integer.MAX_VALUE;\n            int currentLongest = 0;\n\n            for (final Map.Entry<CharSequence, CharSequence> pair : lookupMap.entrySet()) {\n                mLookupMap.put(pair.getKey().toString(), pair.getValue().toString());\n                mPrefixSet.set(pair.getKey().charAt(0));\n                final int sz = pair.getKey().length();\n                if (sz < currentShortest) {\n                    currentShortest = sz;\n                }\n                if (sz > currentLongest) {\n                    currentLongest = sz;\n                }\n            }\n            mShortest = currentShortest;","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/runner/RunnerUtils.java#L144-L180","documentation":"LookupTranslator's constructor validates its lookupMap argument and throws InvalidParameterException(\"lookupMap cannot be null\") when null is passed. The translator builds internal prefix tables from the map, so a null table cannot yield a functional translator.","triggerScenarios":"Calling new LookupTranslator(null), typically when the map is the result of a lookup that returned null or a nullable field is passed straight through.","commonSituations":"Building a character translator from a config-loaded map that failed to load; passing an uninitialized member variable.","solutions":["Pass an empty map (Collections.emptyMap()) instead of null when no mappings are needed.","Ensure the map is built/loaded before constructing the translator.","Guard the call site: if (map == null) map = new HashMap<>();"],"exampleFix":"// before\nLookupTranslator t = new LookupTranslator(prefs.getTranslatorMap()); // may be null\n// after\nLookupTranslator t = new LookupTranslator(\n    Objects.requireNonNullElse(prefs.getTranslatorMap(), Collections.emptyMap()));","handlingStrategy":"type-guard","validationCode":"if (lookupMap == null) {\n    lookupMap = Collections.emptyMap();\n}\nLookupTranslator t = new LookupTranslator(lookupMap);","typeGuard":"boolean isUsableMap(Map<CharSequence, CharSequence> m) {\n    return m != null;\n}","tryCatchPattern":"try {\n    LookupTranslator t = new LookupTranslator(map);\n} catch (InvalidParameterException e) {\n    t = new LookupTranslator(Collections.emptyMap());\n}","preventionTips":["Never pass nullable map fields straight into constructors.","Default to an empty map when no translations are configured.","Use Objects.requireNonNullElse(map, Map.of()) at call sites."],"tags":["null-check","constructor","arguments"],"backgroundTag":"null-argument","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}