jib icon indicating copy to clipboard operation
jib copied to clipboard

Warning to use java.time-based API in jib-core Retry.java

Open chanseokoh opened this issue 5 years ago • 2 comments

(logs from https://travis-ci.org/github/GoogleContainerTools/jib/jobs/676290173)

> Task :jib-core:compileJava
/home/travis/build/GoogleContainerTools/jib/jib-core/src/main/java/com/google/cloud/tools/jib/cache/Retry.java:104: warning: [PreferJavaTimeOverload] Prefer using java.time-based APIs when available. Note that this checker does not and cannot guarantee that the overloads have equivalent semantics, but that is generally the case with overloaded methods.
    this.sleepMilliseconds = unit.convert(duration, TimeUnit.MILLISECONDS);
                                         ^
    (see https://errorprone.info/bugpattern/PreferJavaTimeOverload)
  Did you mean 'this.sleepMilliseconds = unit.convert(Duration.ofMillis(duration));'?
1 warning

chanseokoh avatar Apr 17 '20 17:04 chanseokoh

Is this the Java11 build?

loosebazooka avatar Apr 17 '20 17:04 loosebazooka

Yeah, seems like only on Java 11.

The Error Prone page says

APIs that require a long, TimeUnit pair suffer from a number of problems

  1. they may require plumbing 2 parameters through various layers of your application
  2. overflows are possible when doing duration math
  3. they lack semantic meaning (when viewed separately)
  4. decomposing a duration into a long, TimeUnit is dangerous because of unit mismatch and/or excessive truncation.

chanseokoh avatar Apr 17 '20 17:04 chanseokoh