检查器框架 initialization.fields.uninitialize 误报

Checker Framework initialization.fields.uninitialize false positive

这是我的错误

  found   : @Initialized @Nullable String
  required: @Initialized @NonNull String
/Users/calebcushing/IdeaProjects/ppm/scaf/src/main/java/com/xenoterracide/scaf/Application.java:21: error: [initialization.fields.uninitialized] the constructor does not initialize fields: arg, args, dir
public final class Application implements Runnable {
             ^
3 errors

这些由 picocli 初始化,所以我添加了 SuppressWarnings,不确定为什么它仍然发生。

  @SuppressWarnings({ "NullAway.Init", "initialization.fields.uninitialize" })
  @CommandLine.Parameters( index = "0", description = "first configuration directory" )
  private String arg;

  @SuppressWarnings({ "NullAway.Init", "initialization.fields.uninitialize" })
  @CommandLine.Parameters(
    index = "1..*",
    description = "path to configuration directories separated by space"
  )
  private List<String> args;

  @SuppressWarnings({ "NullAway.Init", "initialization.fields.uninitialize" })
  @CommandLine.Option(
    names = {"-d", "--dir"},
    defaultValue = ".config/scaf",
    showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
    description = "Directory path from the current working directory. " +
      "Templates and configs are looked up relative to here"
  )
  private Path dir;

我试过

  @SuppressWarnings({ "NullAway.Init", "initialization.fields.uninitialize"})

在 class 上,构造函数和如您所见的字段。如何使 checkerframework 快乐?

here is the full source code 当前未在其中启用检查器框架,因为如果我启用了它就无法编译。

Checker 框架正在抱怨,因为在您的 main 方法中您没有初始化实例字段 argargsdir。如果你没有明确地注释一个字段,从检查器框架的角度来看,该字段被认为是 @NotNull.

请尝试用 @Nullable:

注释该字段
  @CommandLine.Parameters( index = "0", description = "first configuration directory" )
  private @Nullable String arg;

  @CommandLine.Parameters(
    index = "1..*",
    description = "path to configuration directories separated by space"
  )
  private @Nullable List<String> args;

  @CommandLine.Option(
    names = {"-d", "--dir"},
    defaultValue = ".config/scaf",
    showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
    description = "Directory path from the current working directory. " +
      "Templates and configs are looked up relative to here"
  )
  private @Nullable Path dir;

虽然你配置了picocli提供默认值,但是checker framework只知道main方法调用后这些字段没有初始化,没有这样的初始化代码,picocli将提供您指定的默认值,但检查器框架不知道这一点,这就是它抱怨它的原因。

话虽如此,如果您希望抑制警告,请注意检查器框架指示必须抑制的警告类型,initialization.fields.uninitialized,您的代码似乎有错字:

@SuppressWarnings({ "NullAway.Init", "initialization.fields.uninitialize" })

请注意所需值 initialization.fields.uninitialized 与您提供的值 initialization.fields.uninitialize 之间的差异。