Примеры ошибок, обнаруженных с помощью диагностики V6082
V6082. Unsafe double-checked locking.
WildFly
V6082 Unsafe double-checked locking. A previously assigned object may be replaced by another object. JspApplicationContextWrapper.java(74), JspApplicationContextWrapper.java(72)
private volatile ExpressionFactory factory;
....
@Override
public ExpressionFactory getExpressionFactory() {
if (factory == null) {
synchronized (this) {
if (factory == null) {
factory = delegate.getExpressionFactory();
for (ExpressionFactoryWrapper wrapper : wrapperList) {
factory = wrapper.wrap(factory, servletContext);
}
}
}
}
return factory;
}
DBeaver
V6082 Unsafe double-checked locking. The field should be declared as volatile. TaskImpl.java(59), TaskImpl.java(317)
private List<DBTTaskRun> runs;
....
private void loadRunsIfNeeded() {
if (runs == null) {
synchronized (this) {
if (runs == null) {
runs = new ArrayList<>(loadRunStatistics());
}
}
}
}
Keycloak
V6082 Unsafe double-checked locking. The field should be declared as volatile. WelcomeResource.java 77 , WelcomeResource.java 257
public class WelcomeResource {
private AtomicBoolean shouldBootstrap;
....
private boolean shouldBootstrap() {
if (shouldBootstrap == null) {
synchronized (this) {
if (shouldBootstrap == null) {
shouldBootstrap = new AtomicBoolean(....);
}
}
}
return shouldBootstrap.get();
}
Keycloak
V6082 Unsafe double-checked locking. The field should be declared as volatile. DefaultFreeMarkerProviderFactory.java 13 , DefaultFreeMarkerProviderFactory.java 20
public class DefaultFreeMarkerProviderFactory
implements FreeMarkerProviderFactory {
private DefaultFreeMarkerProvider provider; // <=
....
public DefaultFreeMarkerProvider create(KeycloakSession session) {
if (provider == null) {
synchronized (this) {
if (provider == null) {
if (Config.scope("theme").getBoolean("cacheTemplates", true)) {
cache = new ConcurrentHashMap<>();
}
kcSanitizeMethod = new KeycloakSanitizerMethod();
provider = new DefaultFreeMarkerProvider(cache, kcSanitizeMethod);
}
}
}
return provider;
}
}