{"record":{"id":"2d1a31ce578462f2","repo":"MuntashirAkon/AppManager","slug":"flags-must-be-returned-by-the-corresponding-subclasses-key","errorCode":null,"errorMessage":"Flags must be returned by the corresponding subclasses. key: ${key}","messagePattern":"Flags must be returned by the corresponding subclasses\\. key: (.+?)","errorType":"validation","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java","lineNumber":145,"sourceCode":"                case TYPE_LONG:\n                case TYPE_TIME_MILLIS:\n                case TYPE_DURATION_MILLIS:\n                case TYPE_SIZE_BYTES:\n                    this.longValue = Long.parseLong(value);\n                    break;\n                case TYPE_REGEX:\n                    this.regexValue = Pattern.compile(Pattern.quote(value));\n                case TYPE_STR_MULTIPLE:\n                    this.stringValues = value.split(\"\\\\n\");\n            }\n        }\n    }\n\n    @NonNull\n    public abstract Map<String, Integer> getKeysWithType();\n\n    public Map<Integer, CharSequence> getFlags(String key) {\n        throw new UnsupportedOperationException(\"Flags must be returned by the corresponding subclasses. key: \" + key);\n    }\n\n    @NonNull\n    public abstract TestResult test(@NonNull IFilterableAppInfo info, @NonNull TestResult result);\n\n    @NonNull\n    @Override\n    public String toString() {\n        return \"FilterOption{\" +\n                \"type='\" + type + '\\'' +\n                \", id=\" + id +\n                \", key='\" + key + '\\'' +\n                \", keyType=\" + keyType +\n                \", value='\" + value + '\\'' +\n                '}';\n    }\n\n    @Override","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java#L127-L163","documentation":"FilterOption.getFlags(key) is an intentionally unimplemented base-class method: only subclasses that define flag keys override it. The base implementation throws UnsupportedOperationException to signal that flag lookup must be handled by the concrete option subclass.","triggerScenarios":"Calling getFlags(key) on a FilterOption reference whose concrete class does not override getFlags for that key; calling flagsToString(key, flags) (which calls getFlags) on a non-flag key or on a base-typed option that lacks the override.","commonSituations":"Generic UI code iterating all filter options and asking for flags of every key; adding a new TYPE_INT_FLAGS key to a subclass but forgetting to override getFlags; calling getFlags on a key whose keyType is not TYPE_INT_FLAGS.","solutions":["Override getFlags(String key) in the concrete FilterOption subclass and return the flag map for its flag keys.","Only call getFlags for keys whose keyType is TYPE_INT_FLAGS.","Route flag lookup through flagsToString()/getFlags on the concrete subclass type rather than the abstract base."],"exampleFix":"// before\n@Override\npublic Map<Integer, CharSequence> getFlags(String key) { /* not overridden -> base throws */ }\n// after\n@Override\npublic Map<Integer, CharSequence> getFlags(@NonNull String key) {\n    if (key.equals(\"with_flags\") || key.equals(\"without_flags\")) return mFlags;\n    return super.getFlags(key);\n}","handlingStrategy":"type-guard","validationCode":"if (option.getKeyType() == FilterOption.TYPE_INT_FLAGS) {\n    Map<Integer, CharSequence> flags = option.getFlags(key);\n}","typeGuard":"static boolean supportsFlags(FilterOption o, String key) {\n    return o.getKeyType() == FilterOption.TYPE_INT_FLAGS && !(o instanceof FilterOption) == false && o.getClass() != FilterOption.class;\n}","tryCatchPattern":"try {\n    flags = option.getFlags(key);\n} catch (UnsupportedOperationException e) {\n    flags = Collections.emptyMap();\n}","preventionTips":["Only request flags for keys whose keyType is TYPE_INT_FLAGS.","Always override getFlags() in subclasses that define flag keys.","Call via the concrete subclass type when possible."],"tags":["java","android","unsupported-operation","abstract-method"],"backgroundTag":"method-not-implemented","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"}