sabertiger commented on PR #5024: URL: https://github.com/apache/hadoop/pull/5024#issuecomment-1290897482
> i really like the tests; you've gone to a lot of effort to show how the code is broken. > > i do think we can simplify the production code though. > > can't we just make init() synchronized and then postpone setting initialized.set(true) to a finally() clause. the check at the beginning should become > > ``` > protected synchronized void init() throws IOException { > if (isInitialized()) { > return; > } > try { > awsCredentials = Invoker.once("create credentials", "", > () -> createCredentials(getConf())); > } catch (IOException e) { > initializationException = e; > throw e; > } finally { > initialized.set(true) > } > } > ``` > > we would also want to have > > 1. getCredentials() rethrow any IOE in initializationException > 2. decide what to do about hasCredentials(). It's not used in the codebase that I can see; i can't rememember why it is there. maybe have it call init() too. Incorporated suggestions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org