-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue/277 #285
Conversation
Kudos, SonarCloud Quality Gate passed! |
@@ -273,12 +277,14 @@ public long capacity() { | |||
@Override | |||
public long addressForRead(long offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add @nonnegative annotation to these for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I believe that offsets should always be from the start of the Bytes and thus always be >= 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should. This makes the contract clearer. I have raised #290
@@ -273,12 +277,14 @@ public long capacity() { | |||
@Override | |||
public long addressForRead(long offset) | |||
throws UnsupportedOperationException, IllegalStateException, BufferUnderflowException { | |||
requireNonNegative(offset); | |||
return base.addressForRead(offset); | |||
} | |||
|
|||
@Override | |||
public long addressForWrite(long offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here?
@@ -881,6 +896,7 @@ public void readWithLength(Bytes bytes) | |||
@NotNull | |||
public Bytes<Void> writePosition(long position) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here?
@@ -1106,11 +1122,11 @@ private void doIndent() { | |||
|
|||
@Override | |||
@NotNull | |||
public Bytes<Void> write(@NotNull byte[] bytes, int offset, int length) | |||
public Bytes<Void> write(@NotNull byte[] byteArray, int offset, int length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use @NotNull for byte arrays sometimes and not other times (even though we assert not null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally there was a misunderstanding about what @NotNull
means for arrays. I raised a new issue about this:
#291
@@ -1655,6 +1674,9 @@ public Bytes write(@NotNull InputStream inputStream) | |||
@Override | |||
public Bytes<Void> write(@NotNull BytesStore bytes, long offset, long length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1709,6 +1731,8 @@ public Bytes write(@NotNull InputStream inputStream) | |||
@Override | |||
public void writePositionRemaining(long position, long length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemed to be some inconsistencies with our use of the annotations, but other than that LGTM! |
final byte[] byteArray, | ||
@NonNegative final int offset, | ||
@NonNegative final int length) throws IllegalStateException { | ||
requireNonNegative(offsetInRDO); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My dream is that we (and customers) can validate @NonNegative
etc at compile time using static analysis, and we can turn off checks at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is absolutely doable. We could clone and modify the current non-null plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the additional tests and rigour but I would be much happier if we bolstered our performance tests for common use cases
This PR introduces additional tests and checkings around negative values. This prevents a number of bugs and JVM crashes in the tests.