{"record":{"id":"a420657d1653220d","repo":"HMCL-dev/HMCL","slug":"grant-flow","errorCode":null,"errorMessage":"grant flow ","messagePattern":"grant flow ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/auth/OAuth.java","lineNumber":65,"sourceCode":"    private final String deviceCodeURL;\n    private final String tokenURL;\n\n    public OAuth(String authorizationURL, String accessTokenURL, String deviceCodeURL, String tokenURL) {\n        this.authorizationURL = authorizationURL;\n        this.accessTokenURL = accessTokenURL;\n        this.deviceCodeURL = deviceCodeURL;\n        this.tokenURL = tokenURL;\n    }\n\n    public Result authenticate(GrantFlow grantFlow, Options options) throws AuthenticationException {\n        try {\n            switch (grantFlow) {\n                case AUTHORIZATION_CODE:\n                    return authenticateAuthorizationCode(options);\n                case DEVICE:\n                    return authenticateDevice(options);\n                default:\n                    throw new UnsupportedOperationException(\"grant flow \" + grantFlow);\n            }\n        } catch (IOException e) {\n            throw new ServerDisconnectException(e);\n        } catch (InterruptedException e) {\n            throw new NoSelectedCharacterException();\n        } catch (ExecutionException e) {\n            if (e.getCause() instanceof InterruptedException) {\n                throw new NoSelectedCharacterException();\n            } else {\n                throw new ServerDisconnectException(e);\n            }\n        } catch (JsonParseException e) {\n            throw new ServerResponseMalformedException(e);\n        }\n    }\n\n    private Result authenticateAuthorizationCode(Options options) throws IOException, InterruptedException, JsonParseException, ExecutionException, AuthenticationException {\n        try (Session session = options.callback.startServer()) {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/OAuth.java#L47-L83","documentation":"OAuth.authenticate switches on the configured grantFlow. Only AUTHORIZATION_CODE and DEVICE are implemented; any other GrantFlow value reaches the default branch and throws UnsupportedOperationException. It marks an unimplemented enum value, typically from a custom or newly added flow.","triggerScenarios":"Constructing an OAuth authenticator with a grantFlow other than AUTHORIZATION_CODE or DEVICE (e.g. CLIENT_CREDENTIALS or a custom enum constant) and calling authenticate.","commonSituations":"Adding a new GrantFlow enum constant without wiring it into authenticate; copy-pasted configuration selecting an unsupported flow.","solutions":["Use GrantFlow.AUTHORIZATION_CODE or GrantFlow.DEVICE","If you added a new GrantFlow value, implement its branch in OAuth.authenticate","Log/inspect the configured flow value to confirm what is being passed"],"exampleFix":"// before\nnew OAuth(GrantFlow.PASSWORD, options).authenticate();\n// after\nnew OAuth(GrantFlow.AUTHORIZATION_CODE, options).authenticate();","handlingStrategy":"validation","validationCode":"if (grantFlow != GrantFlow.AUTHORIZATION_CODE && grantFlow != GrantFlow.DEVICE) {\n    throw new IllegalArgumentException(\"Unsupported grant flow: \" + grantFlow);\n}","typeGuard":"boolean supported = grantFlow == GrantFlow.AUTHORIZATION_CODE || grantFlow == GrantFlow.DEVICE;","tryCatchPattern":"try {\n    return oauth.authenticate();\n} catch (UnsupportedOperationException e) {\n    log.error(\"Grant flow not implemented: {}\", e.getMessage());\n}","preventionTips":["Restrict configuration to implemented GrantFlow values","Add an enum completeness check/test over GrantFlow","When adding enum constants, update the authenticate switch"],"tags":["oauth","enum","unsupported-operation"],"backgroundTag":"unsupported-enum-value","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}