Juan Hernandez has posted comments on this change. Change subject: fixing integer out of range exception in search ......................................................................
Patch Set 6: (2 comments) http://gerrit.ovirt.org/#/c/23488/6/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/SyntaxChecker.java File backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/SyntaxChecker.java: Line 959: case Range: Line 960: result = Line 961: StringFormat.format(pagingSyntax, Line 962: BigInteger.valueOf((page - 1) * syntax.getMaxCount() + 1), Line 963: BigInteger.valueOf(page * syntax.getMaxCount())); This doesn't take advantage of the BigInteger, as the calculation is done with plain integers, which may overflow before calling BigInteger.valueOf. You need to do something like this: BigInteger bigPage = BigInteger.valueOf(page); BigInteger bigCount = BigInteger.valueOf(sytanx.getMaxCount()); BigInteger bigX = bigPage.subtract(BigInteger.ONE).multiply(bigCount).add(BigInteger.ONE); BigInteger bigY = bigPage.multiply(bigCount); result = StringFormat.format(pagingSyntax, bigX, bigY); It is ugly, and hard to read, I know, but that way you are 100% sure that there are no overflows in the JVM. Line 964: break; Line 965: case Offset: Line 966: result = StringFormat.format(pagingSyntax, BigInteger.valueOf((page - 1) * syntax.getMaxCount() + 1), syntax.getMaxCount()); Line 967: break; Line 962: BigInteger.valueOf((page - 1) * syntax.getMaxCount() + 1), Line 963: BigInteger.valueOf(page * syntax.getMaxCount())); Line 964: break; Line 965: case Offset: Line 966: result = StringFormat.format(pagingSyntax, BigInteger.valueOf((page - 1) * syntax.getMaxCount() + 1), syntax.getMaxCount()); Same here. Line 967: break; Line 968: } Line 969: } Line 970: -- To view, visit http://gerrit.ovirt.org/23488 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I518dfdfff93dde28d9741d5e333c695239b7e7d2 Gerrit-PatchSet: 6 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Eli Mesika <[email protected]> Gerrit-Reviewer: Eli Mesika <[email protected]> Gerrit-Reviewer: Juan Hernandez <[email protected]> Gerrit-Reviewer: Yair Zaslavsky <[email protected]> Gerrit-Reviewer: oVirt Jenkins CI Server Gerrit-HasComments: Yes _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
