This repository was archived by the owner on Mar 7, 2025. It is now read-only.
Description StoredSecret interface looks like a good candidate to be AutoCloseable. So instead of this abomination from the sample code
private void userLogin () {
log .info ("Authenticating a user" );
final StoredCredential enteredCredential = enterCredentials ();
StoredCredential storedCredential = null ;
try {
// Save the credential to the store.
storedCredential = credentialStorage .get (CREDENTIALS_KEY );
if (storedCredential .equals (enteredCredential )) {
log .info ("User logged in successfully." );
} else {
log .info ("Authentication failed." );
}
} finally {
// clear password value
enteredCredential .clear ();
if (storedCredential != null ) {
storedCredential .clear ();
}
}
}
you could write this beauty
private void userLogin () {
log .info ("Authenticating a user" );
try (StoredCredential enteredCredential = enterCredentials ();
StoredCredential storedCredential = credentialStorage .get (CREDENTIALS_KEY )) {
if (storedCredential .equals (enteredCredential )) {
log .info ("User logged in successfully." );
} else {
log .info ("Authentication failed." );
}
}
}Reactions are currently unavailable
StoredSecretinterface looks like a good candidate to beAutoCloseable. So instead of this abomination from the sample codeyou could write this beauty