{"record":{"id":"78ac3b69dc69a236","repo":"pxb1988/dex2jar","slug":"can-t-convert-value-to-type-type","errorCode":null,"errorMessage":"can't convert [${value}] to type ${type}","messagePattern":"can't convert \\[(.+?)\\] to type (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"d2j-base-cmd/src/main/java/com/googlecode/dex2jar/tools/BaseCmd.java","lineNumber":279,"sourceCode":"        if (type.equals(double.class) || type.equals(Double.class)) {\n            return Double.parseDouble(value);\n        }\n        if (type.equals(boolean.class) || type.equals(Boolean.class)) {\n            return Boolean.parseBoolean(value);\n        }\n        if (type.equals(File.class)) {\n            return new File(value);\n        }\n        if (type.equals(Path.class)) {\n            return new File(value).toPath();\n        }\n        try {\n            type.asSubclass(Enum.class);\n            return Enum.valueOf(type, value);\n        } catch (Exception ignored) {\n        }\n\n        throw new RuntimeException(\"can't convert [\" + value + \"] to type \" + type);\n    }\n\n    protected abstract void doCommandLine() throws Exception;\n\n    public void doMain(String... args) {\n        try {\n            initOptions();\n            parseSetArgs(args);\n            doCommandLine();\n        } catch (HelpException e) {\n            String msg = e.getMessage();\n            if (msg != null && msg.length() > 0) {\n                System.err.println(\"ERROR: \" + msg);\n            }\n            usage();\n        } catch (Exception e) {\n            e.printStackTrace(System.err);\n        }","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/d2j-base-cmd/src/main/java/com/googlecode/dex2jar/tools/BaseCmd.java#L261-L297","documentation":"convert() maps a raw command-line string to a typed field value; for enum-typed options it does Enum.valueOf(type, value) and, on any failure (bad constant, wrong type), throws a RuntimeException with this message. It is dex2jar's generic 'this option value is not valid for the target type' error.","triggerScenarios":"Passing a CLI option whose declared field is an enum type but whose value does not match any enum constant name (exact, case-sensitive match required), e.g. --log-level verbose when the enum defines only ERROR/WARN/INFO/DEBUG.","commonSituations":"Typo or wrong casing of enum constants; using a human-friendly value like 'warn' instead of 'WARN'; passing a number for an enum option; changes in enum constants between dex2jar versions.","solutions":["Use the exact enum constant name with correct casing for that option","Run the tool with -h/--help to list allowed values for the option","Check the enum type named in the message (e.g. class com...Level) and pick one of its constants","If scripting, match values against the enum in your wrapper script"],"exampleFix":"// before\n./d2j-dex2jar.sh -f app.apk --log-level verbose\n// after\n./d2j-dex2jar.sh -f app.apk --log-level DEBUG","handlingStrategy":"validation","validationCode":"// validate enum option value before invoking\ndef validEnum(type, value) {\n  try { Enum.valueOf(type, value); return true } catch (e) { return false }\n}\nassert validEnum(com.googlecode.dex2jar.tools.Level.class, \"DEBUG\")","typeGuard":null,"tryCatchPattern":"try {\n  tool.doMain(args);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"can't convert [\")) {\n    System.err.println(\"Bad option value; run with -h for allowed values\");\n  } else throw e;\n}","preventionTips":["Always match enum constants exactly, including casing","Consult -h/--help output for the accepted value list of each option","Quote enum-like values in shell scripts to avoid casing/spacing surprises","Pin your scripts to a known dex2jar version since enum options can change"],"tags":["cli","parsing","enum","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}