kamaci commented on a change in pull request #6662: Double-checked locking bugs
URL: https://github.com/apache/incubator-druid/pull/6662#discussion_r237839855
##########
File path:
aws-common/src/main/java/org/apache/druid/common/aws/LazyFileSessionCredentialsProvider.java
##########
@@ -32,14 +32,10 @@ public
LazyFileSessionCredentialsProvider(AWSCredentialsConfig config)
this.config = config;
}
- private FileSessionCredentialsProvider getUnderlyingProvider()
+ private synchronized FileSessionCredentialsProvider getUnderlyingProvider()
Review comment:
Here is the implementation with reference to _Effective Java, Second Edition
Item 71: Use lazy initialization judiciously_:
```java
private final AWSCredentialsConfig config;
/* The field is declared volatile in order to ensure safe publication of
the object
without worrying about final modifiers on the fields of the created
object */
@Nullable
private volatile FileSessionCredentialsProvider provider;
public LazyFileSessionCredentialsProvider(AWSCredentialsConfig config)
{
this.config = config;
}
//FileSessionCredentialsProvider is safely initialized because it contains
a final field sessionCredentials.
private FileSessionCredentialsProvider getUnderlyingProvider() {
FileSessionCredentialsProvider syncedProvider = provider;
if (syncedProvider == null) {
synchronized (config) {
syncedProvider = provider;
if (syncedProvider == null) {
syncedProvider = new
FileSessionCredentialsProvider(config.getFileSessionCredentials());
provider = syncedProvider;
}
}
}
return syncedProvider;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]