为什么Map.getOrDefault()要警告NullPointerException?

我有一个Map (多个地图,有几种),签名如下:

代码语言:javascript运行复制Map> motherChildIndex;如果映射中不存在密钥,我更希望它返回一个空集(而不是null),因此我偶然发现了getOrDefault方法,它应该允许我有效地“忽略”空值。

这是我的相关代码:

代码语言:javascript运行复制motherChildIndex

.getOrDefault(personId, Collections.emptySet()) //personId is just a string that may or may not be in the map, hence getOrDefault

.stream() //I get the warning here

.map(personsIndex::get) //Not important to reproduce

.forEach(children::add); //Not important to reproduce在.stream()线路上,我收到一个警告:

方法调用“流”可以生成“java.lang.NullPointerException”

为什么?我以为getOrDefault()不应该返回空的。

我正在使用Android作为我的IDE,如果这有什么区别的话。