-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fixes #10211 - NPE in ArrayByteBufferPool.findOldestEntry() #10212
Conversation
Fixed algorithm to check for oldest entry to avoid NPE. Added comments for clarity. Signed-off-by: Simone Bordet <[email protected]>
jetty-io/src/main/java/org/eclipse/jetty/io/ArrayRetainableByteBufferPool.java
Show resolved
Hide resolved
jetty-io/src/main/java/org/eclipse/jetty/io/ArrayRetainableByteBufferPool.java
Show resolved
Hide resolved
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.
A couple of niggles, but I won't request changes in case I'm out of contact and can't approve any changes. So I'm -0 as is, and +1 with the niggles fixed.
jetty-io/src/main/java/org/eclipse/jetty/io/ArrayRetainableByteBufferPool.java
Outdated
Show resolved
Hide resolved
jetty-io/src/main/java/org/eclipse/jetty/io/ArrayRetainableByteBufferPool.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Simone Bordet <[email protected]>
if (buffer == null) | ||
continue; | ||
long age = NanoTime.elapsed(buffer.getLastUpdate(), now); | ||
if (oldestBuffer != null && age < oldestAge) | ||
continue; | ||
oldestEntry = entry; | ||
oldestBuffer = buffer; | ||
oldestAge = age; |
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.
There you go... you can be both consistent and readable:
if (buffer == null) | |
continue; | |
long age = NanoTime.elapsed(buffer.getLastUpdate(), now); | |
if (oldestBuffer != null && age < oldestAge) | |
continue; | |
oldestEntry = entry; | |
oldestBuffer = buffer; | |
oldestAge = age; | |
if (buffer != null) | |
{ | |
long age = NanoTime.elapsed(buffer.getLastUpdate(), now); | |
if (oldestBuffer == null || age > oldestAge) | |
{ | |
oldestEntry = entry; | |
oldestBuffer = buffer; | |
oldestAge = age; | |
} | |
} |
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.
One niggle left, but I'll approve anyway
@sbordet ... and we should add tests for this... but in another later PR is fine |
@@ -390,13 +392,14 @@ private void evict(boolean direct, long excess) | |||
|
|||
if (oldestEntry.remove()) |
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.
No null check here?
This same code in jetty-12.0.x
has a null check. (yes, i'm aware this PR is for jetty-10.0.x
)
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.
Gee how do you make it include the code here?
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 PR changes ArrayRetainableByteBufferPool.java
in jetty-10.0.x
and is missing that null check.
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'm going to retract and get more sleep
Disregard everything I've said in the last hour. :-(
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.
Signed-off-by: Simone Bordet <[email protected]>
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.
Thanks
Fixed algorithm to check for oldest entry to avoid NPE. Added comments for clarity.