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

call dispatch only when stepBuffer returns true #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jcz2
Copy link

@jcz2 jcz2 commented Jan 25, 2024

Hi,
while using the library in one of our projects we noticed a null pointer exception occuring in the XMemcachedClient:
https://github.com/killme2008/xmemcached/blob/master/src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java#L1215

java.lang.NullPointerException: null
	at net.rubyeye.xmemcached.XMemcachedClient.reduceResult(XMemcachedClient.java:1215)
	at net.rubyeye.xmemcached.XMemcachedClient.getMulti0(XMemcachedClient.java:1202)
	at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1088)
	at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1121)
	at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1110)

This happens because the TextGetCommand.result is not ready yet when the XMemcachedClient.reduceResult method is invoked.

The result is not ready because a single command may reduce the countdown latch more than once by calling dispatch method inside the TextGetCommand.decode method.

The issue is in this part of the code:

if (first == 'E' && second == 'N') {
  // dispatch result
  dispatch();
  this.currentReturnKey = null;
  // END\r\n
  return ByteUtils.stepBuffer(buffer, 5);
}

It calls dispatch when it encounters E followed by N and returns the result of checking whether the buffer contains 5 or more elements. However if there are less than 5 elements remaining in the buffer then the result will be false and the decode method will be called again, entering the same condition and calling dispatch second time.

To avoid this the pull request changes this part of the code to call dispatch only when there are 5 or more elements in the buffer.

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

1 participant