Skip to content

Commit 86f7bca

Browse files
authored
api: Fix boundary check in Status.fromCodeValue() (#10155)
1 parent b4f4142 commit 86f7bca

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

api/src/main/java/io/grpc/Status.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private static List<Status> buildStatusList() {
307307
* Return a {@link Status} given a canonical error {@link Code} value.
308308
*/
309309
public static Status fromCodeValue(int codeValue) {
310-
if (codeValue < 0 || codeValue > STATUS_LIST.size()) {
310+
if (codeValue < 0 || codeValue >= STATUS_LIST.size()) {
311311
return UNKNOWN.withDescription("Unknown code " + codeValue);
312312
} else {
313313
return STATUS_LIST.get(codeValue);

api/src/test/java/io/grpc/StatusTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void verifyExceptionMessage() {
4343
@Test
4444
public void impossibleCodeValue() {
4545
assertEquals(Code.UNKNOWN, Status.fromCodeValue(-1).getCode());
46+
assertEquals(Code.UNKNOWN, Status.fromCodeValue(17).getCode());
4647
}
4748

4849
@Test

0 commit comments

Comments
 (0)