2 x @NotNull == too much?

Jan Nielsen :

The BytesUtil.bytesEqual parameters use both the Jetbrains @NotNull and the OpenHFT @NotNull annotation the same parameter:

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 {

which appears redundant -- is there any reason for using both? The two annotations are (currently) defined as:

package net.openhft.chronicle.core.annotation;

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

and

package org.jetbrains.annotations;

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

so Jetbrains @NotNull provides a default empty string value otherwise the two annotations are the same...so why specify both?

Peter Lawrey :

The problem we had with IntelliJ's annotation is that when byte code instrumentation is enabled, it add a check which throws an IllegalArgumentException. However, when the code is released or run in another context it instead triggers a NullPointerException.

For this reason, we added our own annotation across much of the code base so there would be code analysis checking in IntelliJ without the extra runtime check being added.

Most likely we should only use our annotation everywhere to make the exception thrown deterministic.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=106334&siteId=1