Index: src/main/java/org/apache/jackrabbit/oak/query/FilterIterators.java
===================================================================
--- src/main/java/org/apache/jackrabbit/oak/query/FilterIterators.java	(revision 1652996)
+++ src/main/java/org/apache/jackrabbit/oak/query/FilterIterators.java	(working copy)
@@ -204,7 +204,7 @@
                 // from time to time, sort and truncate
                 // this should results in O(n*log(2*keep)) operations,
                 // which is close to the optimum O(n*log(keep))
-                if (list.size() > max * 2) {
+                if ((long)list.size() > (long)max * 2L) {
                     // remove tail entries right now, to save memory
                     Collections.sort(list, orderBy);
                     keepFirst(list, max);
