Skip to content
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

Merged
merged 5 commits into from Nov 16, 2021
Merged

Issue/277 #285

merged 5 commits into from Nov 16, 2021

Conversation

minborg
Copy link
Contributor

@minborg minborg commented Nov 12, 2021

This PR introduces additional tests and checkings around negative values. This prevents a number of bugs and JVM crashes in the tests.

@sonarcloud
Copy link

sonarcloud bot commented Nov 12, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug B 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

66.7% 66.7% Coverage
3.7% 3.7% Duplication

@@ -273,12 +277,14 @@ public long capacity() {
@Override
public long addressForRead(long offset)
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)

Copy link
Contributor Author

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)
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicktindall
Copy link
Contributor

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);
Copy link
Contributor

@JerryShea JerryShea Nov 16, 2021

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

Copy link
Contributor Author

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.

Copy link
Contributor

@JerryShea JerryShea left a 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

@minborg minborg merged commit a23813b into develop Nov 16, 2021
@minborg minborg deleted the issue/277 branch November 16, 2021 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants