Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
Examples of errors detected by the...

Examples of errors detected by the V6106 diagnostic

V6106. Casting expression to 'X' type before implicitly casting it to other type may be excessive or incorrect.


Quarkus

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:

  • V6106 Casting expression to int type before implicitly casting it to other type may be excessive or incorrect. MongoClients.java 289