checker-framework不兼容的类型参数

huangapple go评论79阅读模式
英文:

checker-framework incompatible types in type argument

问题

我有一些类似这样的代码,我在其中将一个映射存储到Java的ThreadLocal中,

import java.util.*;

class Foo {
  private final ThreadLocal<Map<String, String>> barMap = ThreadLocal.withInitial(HashMap::new);
}

当我从checkerframework启用nullness检查时,我得到了以下错误

错误: [type.argument.type.incompatible] 类型参数中的类型不兼容
   找到: @Initialized @NonNull Map<@Initialized @NonNull String, @Initialized @NonNull String>
   需要: [extends @Initialized @Nullable Object super null]

我不明白如何解决这个问题。

英文:

I have some code like this where I store a map to java threadlocal,

import java.util.*;

class Foo {
  private final ThreadLocal&lt;Map&lt;String, String&gt;&gt; barMap = ThreadLocal.withInitial(HashMap::new);
}

when enabling the nullness check from checkerframework I get

Error: [type.argument.type.incompatible] incompatible types in type argument.
   found   : @Initialized @NonNull Map&lt;@Initialized @NonNull String, @Initialized @NonNull String&gt;
   required: [extends @Initialized @Nullable Object super null]

I don't understand how to resolve this.

答案1

得分: 1

这是Checker Framework中的一个已知问题。您应该抑制这个警告。

Checker Framework目前使用的是Java 7的类型推断算法。Java 8对类型推断进行了重大更改,这要求在Checker Framework中进行重新实现。(Checker Framework本质上是一个独立的编译器。)这个重新实现已经部分完成,但尚未完成。

英文:

This is a known bug in the Checker Framework. You should suppress the warning.

The Checker Framework currently uses the Java 7 type inference algorithm. Java 8 made a major change to type inference, which requires a re-implementation in the Checker Framework. (The Checker Framework is essentially a compiler in its own right.) That re-implementation is partly done, but has not yet been completed.

huangapple
  • 本文由 发表于 2020年7月23日 16:03:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63049612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定