问题
Here's my error (and yes there is an open bug on commons-lang3 jira).
found : @Initialized @Nullable Console
required: @Initialized @NonNull Console
/Users/calebcushing/IdeaProjects/ppm/scaf/src/main/java/com/xenoterracide/scaf/PebbleTemplateProcessor.java:96: error: [argument.type.incompatible] incompatible argument for parameter str of toBoolean.
if ( BooleanUtils.toBoolean( line ) ) {
I tried making this src/java/main/org/apache/commons/lang3/BooleanUtils.astub
and I tried putting that file in src/main/resources/
package org.apache.commons.lang3;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public class BooleanUtils {
@NonNull
public static boolean toBoolean( @Nullable final String str);
}
but I and adding this to my gradle config
extraJavacArgs.addAll(listOf(
"-Werror",
"-Astubs=BooleanUtils.astub:stubs"
))
but I get
warning: Did not find stub file BooleanUtils.astub on classpath or within current directory
warning: Did not find stub file stubs on classpath or within current directory
how do I fix this issue?
回答1:
I figured it out, no thanks to https://checkerframework.org/manual/#stub, the gradle plugin actually has a useful example of just this https://github.com/kelloggm/checkerframework-gradle-plugin#providing-checker-specific-options-to-the-compiler
you need to provide a path from the project itself, this is what I did.
extraJavacArgs.addAll(listOf(
"-Werror",
"-Astubs=${rootDir}/config/checker/stubs/BooleanUtils.astub"
))
I used ${rootDir}
because ./config...
was looking in .gradle
来源:https://stackoverflow.com/questions/65245508/checker-framework-argument-type-incompatible-false-positive-with-commons-lang3