diff --git a/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java index 9139e58359..1203420323 100644 --- a/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java @@ -424,11 +424,17 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl // requery using the previous maxAssocId minAssocId = maxAssocId; // Double the range multiplier if we have a low hit-rate (<50% of desired size) - if (rows.size() < queryMaxResults / 2) + // and we can avoid integer overflow + if (rows.size() < queryMaxResults / 2 ) { - rangeMultiplier *= 2L; + long newRangeMultiplier = rangeMultiplier * 2L; + long newIdRange = maxResults * newRangeMultiplier; + if (newIdRange > 0 && newIdRange < maxIdRange) + { + rangeMultiplier = newRangeMultiplier; } } + } catch (Throwable e) { // Hit a DB problem. Log all the details of the query so that parameters can be adjusted externally.