2 x @NotNull == 太多了?

2 x @NotNull == too much?

BytesUtil.bytesEqual 参数使用 Jetbrains @NotNull 和 OpenHFT @NotNull 注释相同的参数:

public static boolean bytesEqual(
        @org.jetbrains.annotations.NotNull @NotNull RandomDataInput a, long offset,
        @org.jetbrains.annotations.NotNull @NotNull RandomDataInput second, long secondOffset, long len)
        throws BufferUnderflowException {

这似乎是多余的 -- 是否有理由同时使用两者?这两个注释(当前)定义为:

package net.openhft.chronicle.core.annotation;

@Documented
@Retention(CLASS)
@Target({METHOD, FIELD, PARAMETER, LOCAL_VARIABLE})
public @interface NotNull {
}

package org.jetbrains.annotations;

@Documented
@Retention(CLASS)
@Target({METHOD, FIELD, PARAMETER, LOCAL_VARIABLE})
public @interface NotNull {
  String value() default "";
}

所以 Jetbrains @NotNull 提供了一个默认的空字符串值,否则两个注释是相同的...那么为什么要指定两者?

我们在 IntelliJ 注释中遇到的问题是,当启用字节码检测时,它会添加一个抛出 IllegalArgumentException 的检查。但是,当代码在另一个上下文中发布或 运行 时,它会触发 NullPointerException.

出于这个原因,我们在大部分代码库中添加了自己的注释,这样 IntelliJ 中就可以进行代码分析检查,而无需添加额外的运行时间检查。

很可能我们应该只在任何地方使用我们的注释来使抛出的异常具有确定性。