vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.66k stars 627 forks source link

mapFailure unchecked generic array creation #2647

Open xenoterracide opened 3 years ago

xenoterracide commented 3 years ago
  @Override
  default Path getConfigDir() {
    return Try.ofSupplier( this::getClass )
      .map( Class::getClassLoader )
      .map( cl -> cl.getResource( "config" ) )
      .filter( Objects::nonNull )
      .mapTry( URL::toURI )
      .map( Path::of )
      .mapFailure(
        API.Case( API.$( Predicates.instanceOf( URIException.class ) ), Function.identity() ) )
      .get();
  }

I'm getting

warning: [unchecked] unchecked generic array creation for varargs parameter of type Case<? extends Throwable,? extends Throwable>[]
      .mapFailure(
                 ^
1 warning

would be nice not to get that. I see that the code has the @SuppressWarnings so I'm not entirely certain what Java 11 is up to.

------------------------------------------------------------
Gradle 6.8.3
------------------------------------------------------------

Build time:   2021-02-22 16:13:28 UTC
Revision:     9e26b4a9ebb910eaa1b8da8ff8575e514bc61c78

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.10 (AdoptOpenJDK 11.0.10+9)
OS:           Linux 5.10.19-1-MANJARO amd64
io.vavr:vavr:0.+ -> 0.10.3
\--- runtimeClasspath
danieldietrich commented 3 years ago

I think Try.mapFailure(...) needs to be annotated with @SafeVarargs. This surpasses warnings at the call site.

A programmer assertion that the body of the annotated method or constructor does not perform potentially unsafe operations on its varargs parameter. Applying this annotation to a method or constructor suppresses unchecked warnings about a non-reifiable variable arity (vararg) type and suppresses unchecked warnings about parameterized array creation at call sites.