{"record":{"id":"17284b3966a68235","repo":"apache/beam","slug":"username-is-required-for-password-and-private-key","errorCode":null,"errorMessage":"username is required for password and private key authentication.","messagePattern":"username is required for password and private key authentication\\.","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/SnowflakeSchemaTransformUtils.java","lineNumber":111,"sourceCode":"      authenticationMethods++;\n    }\n\n    if (isNotEmpty(oauthToken)) {\n      authenticationMethods++;\n    }\n\n    if (isNotEmpty(privateKey)) {\n      authenticationMethods++;\n    }\n\n    if (authenticationMethods != 1) {\n      throw new IllegalArgumentException(\n          \"Exactly one authentication method must be configured: \"\n              + \"password, oauthToken, or privateKey.\");\n    }\n\n    if ((isNotEmpty(password) || isNotEmpty(privateKey)) && !isNotEmpty(username)) {\n      throw new IllegalArgumentException(\n          \"username is required for password and private key authentication.\");\n    }\n\n    if (isNotEmpty(privateKeyPassphrase) && !isNotEmpty(privateKey)) {\n      throw new IllegalArgumentException(\"privateKeyPassphrase requires privateKey.\");\n    }\n  }\n\n  @EnsuresNonNullIf(expression = \"#1\", result = true)\n  public static boolean isNotEmpty(@Nullable String value) {\n    return value != null && !value.isEmpty();\n  }\n\n  public static StreamingLogLevel parseStreamingLogLevel(String value) {\n    try {\n      return StreamingLogLevel.valueOf(value);\n    } catch (IllegalArgumentException e) {\n      throw new IllegalArgumentException(","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/SnowflakeSchemaTransformUtils.java#L93-L129","documentation":"validateAuthentication also enforces that when password or privateKey authentication is used, a username must be supplied. Missing username throws IllegalArgumentException('username is required for password and private key authentication.').","triggerScenarios":"Setting password or privateKey but leaving username null/empty in SnowflakeSchemaTransformUtils.validateAuthentication.","commonSituations":"OAuth-only flows reused with a password added but no username; Snowflake usernames with special casing omitted; config templates that assume username comes from the environment.","solutions":["Add the Snowflake username: setUsername(\"MY_USER\").","Ensure the username value resolves to a non-empty string (env var/secret injection).","Switch to oauthToken authentication if no username should be embedded.","Validate the config before submit so the missing field surfaces early."],"exampleFix":"// before\nbuilder.setPrivateKey(pem); // no username\n// after\nbuilder.setPrivateKey(pem).setUsername(\"SNOWFLAKE_USER\");","handlingStrategy":"validation","validationCode":"if ((isNotEmpty(password) || isNotEmpty(privateKey)) && !isNotEmpty(username)) {\n  throw new IllegalArgumentException(\"username is required when using password or privateKey auth\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair username with every password/privateKey configuration.","Verify injected username env/secrets resolve before submit.","Use oauthToken if username capture is problematic."],"tags":["java","snowflake","authentication","validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}