V6106. Casting expression to 'X' type before implicitly casting it to other type may be excessive or incorrect.
V6106 Casting expression to int type before implicitly casting it to other type may be excessive or incorrect. MongoClients.java 286
private static class SocketSettingsBuilder
implements Block<SocketSettings.Builder> {
private final MongoClientConfig config;
@Override
public void apply(SocketSettings.Builder builder) {
if (config.connectTimeout().isPresent()) {
builder.connectTimeout((int) config.connectTimeout().get() // <=
.toMillis(), TimeUnit.MILLISECONDS);
}
}
}
`config.connectTimeout().get().toMillis()` returns long and `builder.connectTimeout(...)` accepts long. Casting to int is redundant and can lead to overflow.
Similar errors can be found in some other places: