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

ZOOKEEPER-4377: KeeperException.create has NullPointerException when low version client requests the high version server #1764

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static KeeperException create(Code code) {
return new ThrottledOpException();
case OK:
default:
throw new IllegalArgumentException("Invalid exception code");
throw new IllegalArgumentException("Invalid exception code:" + code.code);
}
}

Expand Down Expand Up @@ -441,10 +441,14 @@ public int intValue() {
/**
* Get the Code value for a particular integer error code
* @param code int error code
* @return Code value corresponding to specified int code, or null
* @return Code value corresponding to specified int code, if null throws IllegalArgumentException
*/
public static Code get(int code) {
return lookup.get(code);
Code codeVal = lookup.get(code);
if (codeVal == null) {
throw new IllegalArgumentException("The current client version cannot lookup this code:" + code);
}
return codeVal;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

package org.apache.zookeeper;

import static org.apache.zookeeper.KeeperException.Code.NOAUTH;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayOutputStream;
Expand All @@ -31,6 +33,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.zookeeper.AsyncCallback.VoidCallback;
import org.apache.zookeeper.KeeperException.Code;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.cli.CliCommand;
import org.apache.zookeeper.cli.CliException;
Expand Down Expand Up @@ -802,4 +805,14 @@ public void testWaitForConnection() throws Exception {

}

@Test
public void testKeeperExceptionCreateNPE() {
// One existing code
KeeperException k1 = KeeperException.create(Code.get(NOAUTH.intValue()));
assertTrue(k1 instanceof KeeperException.NoAuthException);

// One impossible code
assertThrows(IllegalArgumentException.class, () -> KeeperException.create(Code.get(Integer.MAX_VALUE)));
}

}