3

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?

Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119
  • It's most likely duplicated to reap the benefits of having both. The jetbrains one likely enables IntelliJ to offer better code assistance if it detects that somebody calls that method with `null`. The same is probably true for OpenHFT, for whatever benefit they have for that annotation. Other than this, there's not much more we can definitively say without just pure speculation. – nickb Feb 13 '19 at 20:27

1 Answers1

1

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • But your annotation was added before IntelliJ's. I don't get it but you're the authority on this so heh – Mat Feb 14 '19 at 15:16
  • 1
    @Mat We have discussed this and feel we should either Using IntelliJ's annotations in the maven build or not at all, so we are adding them to the build and removing our annotation. – Peter Lawrey Feb 15 '19 at 18:58