Мы используем куки, чтобы пользоваться сайтом было удобно.
Хорошо
to the top

Вебинар: Go-Go-Gadg...Error? Смотрим, как ошибаются Go разработчики! - 26.08

>
>
>
Примеры ошибок, обнаруженных с...

Примеры ошибок, обнаруженных с помощью диагностики V6106

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