{"record":{"id":"6bc885b7643b386f","repo":"apache/hadoop","slug":"url-cannot-be-null","errorCode":null,"errorMessage":"url cannot be NULL","messagePattern":"url cannot be NULL","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/client/AuthenticatedURL.java","lineNumber":345,"sourceCode":"   */\n  protected Authenticator getAuthenticator() {\n    return authenticator;\n  }\n\n  /**\n   * Returns an authenticated {@link HttpURLConnection}.\n   *\n   * @param url the URL to connect to. Only HTTP/S URLs are supported.\n   * @param token the authentication token being used for the user.\n   *\n   * @return an authenticated {@link HttpURLConnection}.\n   *\n   * @throws IOException if an IO error occurred.\n   * @throws AuthenticationException if an authentication exception occurred.\n   */\n  public HttpURLConnection openConnection(URL url, Token token) throws IOException, AuthenticationException {\n    if (url == null) {\n      throw new IllegalArgumentException(\"url cannot be NULL\");\n    }\n    if (!url.getProtocol().equalsIgnoreCase(\"http\") && !url.getProtocol().equalsIgnoreCase(\"https\")) {\n      throw new IllegalArgumentException(\"url must be for a HTTP or HTTPS resource\");\n    }\n    if (token == null) {\n      throw new IllegalArgumentException(\"token cannot be NULL\");\n    }\n    authenticator.authenticate(url, token);\n\n    // allow the token to create the connection with a cookie handler for\n    // managing session cookies.\n    return token.openConnection(url, connConfigurator);\n  }\n\n  /**\n   * Helper method that injects an authentication token to send with a\n   * connection. Callers should prefer using\n   * {@link Token#openConnection(URL, ConnectionConfigurator)} which","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/client/AuthenticatedURL.java#L327-L363","documentation":"AuthenticatedURL.openConnection(URL, Token) insists on a non-null URL before doing anything else; null triggers IllegalArgumentException('url cannot be NULL'). The method drives the whole SPNEGO/cookie authentication handshake, so without a concrete endpoint there is nothing to authenticate against — hence the immediate reject rather than an NPE deeper in the authenticator.","triggerScenarios":"Passing a URL variable that failed to initialize: new URL on a malformed string threw earlier and was swallowed; configuration key for the web endpoint missing so getUrl() returned null; ternaries that yield null on the untested branch.","commonSituations":"Reading the service endpoint from config whose key is absent in the deployed core-site.xml; environment-specific code paths (prod sets the URL, test does not) reaching production; refactors replacing constants with config lookups without defaults.","solutions":["Validate the URL at configuration-load time: Objects.requireNonNull(url, '...endpoint missing...') with a message naming the config key.","Fail fast at startup with a clear 'missing property X' error instead of deep inside the auth call.","Add unit coverage for the unconfigured path so it is a known, tested failure.","Where the URL comes from user input, parse and reject early with a helpful message."],"exampleFix":"// before\nURL url = getUrlFromConfig(conf); // may be null\nconn = new AuthenticatedURL().openConnection(url, token);\n\n// after\nURL url = getUrlFromConfig(conf);\nif (url == null) { throw new IllegalArgumentException('conf key ' + ENDPOINT_KEY + ' not set'); }\nconn = new AuthenticatedURL().openConnection(url, token);","handlingStrategy":"validation","validationCode":"URL url = getEndpointUrl(conf);\nObjects.requireNonNull(url, \"service endpoint not configured (check \" + ENDPOINT_KEY + \")\");\nnew AuthenticatedURL().openConnection(url, token);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fail fast at configuration load when required endpoints are missing.","Unit-test the unconfigured path so it fails with your message, not the library's.","Prefer non-null URL factories that throw on bad input early."],"tags":["authentication","null-argument","url","hadoop-auth","precondition"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}