diff --git a/source/java/org/alfresco/opencmis/CMISConnector.java b/source/java/org/alfresco/opencmis/CMISConnector.java index 8c466c0d97..78aef1b9c1 100644 --- a/source/java/org/alfresco/opencmis/CMISConnector.java +++ b/source/java/org/alfresco/opencmis/CMISConnector.java @@ -471,6 +471,10 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen { throw new IllegalArgumentException("The default maximum number of content changes to retrieve must be greater than zero."); } + else if (contentChangesDefaultMaxItems == Integer.MAX_VALUE) + { + throw new IllegalArgumentException("The server cannot return " + Integer.MAX_VALUE + " content changes in a request!"); + } this.contentChangesDefaultMaxItems = contentChangesDefaultMaxItems; } @@ -3697,9 +3701,12 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen params.setApplicationName(CMIS_CHANGELOG_AUDIT_APPLICATION); params.setForward(true); params.setFromId(from); - + + // So we have a BigInteger. We need to ensure that we cut it down to an integer smaller than Integer.MAX_VALUE + int maxResults = (maxItems == null ? contentChangesDefaultMaxItems : maxItems.intValue()); maxResults = maxResults < 1 ? contentChangesDefaultMaxItems : maxResults; // Just a double check of the unbundled contents + maxResults = maxResults > contentChangesDefaultMaxItems ? contentChangesDefaultMaxItems : maxResults; // cut it down int queryFor = maxResults + 1; // Query for 1 more so that we know if there are more results auditService.auditQuery(changeLogCollectingCallback, params, queryFor); diff --git a/source/test-java/org/alfresco/opencmis/CMISTest.java b/source/test-java/org/alfresco/opencmis/CMISTest.java index 610d57acf7..7cbdb7a8b0 100644 --- a/source/test-java/org/alfresco/opencmis/CMISTest.java +++ b/source/test-java/org/alfresco/opencmis/CMISTest.java @@ -2600,6 +2600,10 @@ public class CMISTest // and one changes = cmisService.getContentChanges(repositoryId, new Holder(changeToken), Boolean.TRUE, null, Boolean.FALSE, Boolean.FALSE, BigInteger.valueOf(1), null); assertEquals("Expected to still get changes", changes.getObjects().size(), 1); + // Integery.MAX_VALUE must be handled + // This will limit the number to a sane value + changes = cmisService.getContentChanges(repositoryId, new Holder(changeToken), Boolean.TRUE, null, Boolean.FALSE, Boolean.FALSE, BigInteger.valueOf(Integer.MAX_VALUE), null); + assertTrue("Expected to still get changes", changes.getObjects().size() >= expectAtLeast); // but not negative try {