Skip to content

Commit 3676d09

Browse files
authored
Merge pull request #1759 from marklogic/feature/polaris
A raft of Polaris fixes
2 parents 4ed002c + 59a09f5 commit 3676d09

File tree

13 files changed

+56
-220
lines changed

13 files changed

+56
-220
lines changed

examples/src/main/java/com/marklogic/client/example/cookbook/SSLClientCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public X509Certificate[] getAcceptedIssuers() {
5757
};
5858

5959
// create an SSL context
60-
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
60+
SSLContext sslContext = SSLContext.getInstance("TLSv1.3");
6161
/*
6262
* Here, we use a naive TrustManager which would accept any certificate
6363
* which the server produces. But in a real application, there should be a

marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ public CertificateAuthContext(String certFile, String certPassword, X509TrustMan
10301030
this.certFile = certFile;
10311031
this.certPassword = certPassword;
10321032
this.trustManager = trustManager;
1033-
this.sslContext = createSSLContext();
1033+
this.sslContext = createSSLContext(DEFAULT_SSL_PROTOCOL);
10341034
}
10351035

10361036
/**
@@ -1060,11 +1060,6 @@ public CertificateAuthContext(String certFile, String certPassword, X509TrustMan
10601060
this.sslContext = createSSLContext(sslProtocol);
10611061
}
10621062

1063-
private SSLContext createSSLContext()
1064-
throws UnrecoverableKeyException, CertificateException, IOException, KeyManagementException {
1065-
return createSSLContext(DEFAULT_SSL_PROTOCOL);
1066-
}
1067-
10681063
private SSLContext createSSLContext(String sslProtocol)
10691064
throws CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
10701065
if(certPassword == null) {
@@ -1076,12 +1071,14 @@ private SSLContext createSSLContext(String sslProtocol)
10761071
try {
10771072
keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
10781073
} catch (NoSuchAlgorithmException e) {
1074+
SSLUtil.logSecurityRelatedException(e);
10791075
throw new IllegalStateException(
10801076
"CertificateAuthContext requires KeyManagerFactory.getInstance(\"SunX509\")");
10811077
}
10821078
try {
10831079
keyStore = KeyStore.getInstance("PKCS12");
10841080
} catch (KeyStoreException e) {
1081+
SSLUtil.logSecurityRelatedException(e);
10851082
throw new IllegalStateException("CertificateAuthContext requires KeyStore.getInstance(\"PKCS12\")");
10861083
}
10871084
try {
@@ -1100,6 +1097,7 @@ private SSLContext createSSLContext(String sslProtocol)
11001097
sslContext = SSLContext.getInstance(sslProtocol);
11011098
}
11021099
} catch (NoSuchAlgorithmException | KeyStoreException e) {
1100+
SSLUtil.logSecurityRelatedException(e);
11031101
throw new IllegalStateException("The certificate algorithm used or the Key store "
11041102
+ "Service provider Implementaion (SPI) is invalid. CertificateAuthContext "
11051103
+ "requires SunX509 algorithm and PKCS12 Key store SPI", e);
@@ -1291,6 +1289,7 @@ static public DatabaseClient newClient(String host, int port, String basePath, S
12911289
clientConfigurators.forEach(configurator -> {
12921290
if (configurator instanceof OkHttpClientConfigurator) {
12931291
OkHttpClient okHttpClient = (OkHttpClient) services.getClientImplementation();
1292+
Objects.requireNonNull(okHttpClient);
12941293
OkHttpClient.Builder clientBuilder = okHttpClient.newBuilder();
12951294
((OkHttpClientConfigurator) configurator).configure(clientBuilder);
12961295
((OkHttpServices) services).setClientImplementation(clientBuilder.build());

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/QueryBatcherImpl.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ public void run() {
731731
.withForest(forest);
732732

733733
QueryManagerImpl queryMgr = (QueryManagerImpl) client.newQueryManager();
734-
queryMgr.setPageLength(getBatchSize() * getDocToUriBatchRatio());
734+
final long newPageLength = (long)getBatchSize() * (long)getDocToUriBatchRatio();
735+
queryMgr.setPageLength(newPageLength);
735736
UrisHandle handle = new UrisHandle();
736737

737738
if (consistentSnapshot == true && serverTimestamp.get() > -1) {
@@ -881,11 +882,13 @@ private void processDocs(QueryBatchImpl batch) {
881882
logger.error("Exception thrown by an onQueryFailure listener", e2);
882883
}
883884
}
884-
if (retryForestMap.get(forest).get() == 0) {
885-
isDone.set(true);
886-
} else {
887-
retryForestMap.get(forest).decrementAndGet();
888-
}
885+
AtomicInteger forestRetryCounter = retryForestMap.get(forest);
886+
Objects.requireNonNull(forestRetryCounter);
887+
if (forestRetryCounter.get() == 0) {
888+
isDone.set(true);
889+
} else {
890+
forestRetryCounter.decrementAndGet();
891+
}
889892
} else if (t instanceof RuntimeException) {
890893
throw (RuntimeException) t;
891894
} else {
@@ -905,7 +908,8 @@ private void launchNextTask() {
905908
shutdownIfAllForestsAreDone();
906909
return;
907910
}
908-
long nextStart = start + getBatchSize() * getDocToUriBatchRatio();
911+
final long interval = (long)getBatchSize() * (long)getDocToUriBatchRatio();
912+
long nextStart = start + interval;
909913
threadPool.execute(new QueryTask(
910914
moveMgr, batcher, forest, QueryBatcherImpl.this.queryMethod, query, filtered, forestBatchNum + getBatchSize(), nextStart, null, nextAfterUri
911915
));

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/RowBatcherImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RowBatcherImpl<T> extends BatcherImpl implements RowBatcher<T> {
6363
this.rowsHandle = rowsHandle;
6464

6565
DatabaseClient databaseClient = getPrimaryClient();
66-
assert databaseClient != null;
66+
Objects.requireNonNull(databaseClient);
6767
defaultRowManager = databaseClient.newRowManager();
6868

6969
super.withBatchSize(DEFAULT_BATCH_SIZE);

marklogic-client-api/src/main/java/com/marklogic/client/impl/BaseProxy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public BaseProxy(String endpointDir, JSONWriteHandle serviceDeclaration) {
5151
init(endpointDir);
5252
} else {
5353
JsonNode serviceDecl = NodeConverter.handleToJsonNode(serviceDeclaration);
54+
Objects.requireNonNull(serviceDecl);
5455

5556
JsonNode endpointDirProp = serviceDecl.get("endpointDirectory");
5657
if (endpointDirProp == null) {

marklogic-client-api/src/main/java/com/marklogic/client/impl/CombinedQueryBuilderImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ private String makeXMLCombinedQuery(CombinedQueryDefinitionImpl qdef) {
301301
if ( value instanceof OutputStreamSender ) {
302302
((OutputStreamSender) value).write(out);
303303
} else {
304-
out.write(HandleAccessor.contentAsString(options).getBytes("UTF-8"));
304+
String content = HandleAccessor.contentAsString(options);
305+
if (content != null) {
306+
out.write(content.getBytes("UTF-8"));
307+
}
305308
}
306309
out.flush();
307310
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/DatabaseClientPropertySource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,15 @@ private SSLUtil.SSLInputs useNewSSLContext(String sslProtocol, X509TrustManager
440440
try {
441441
sslContext = SSLContext.getInstance(sslProtocol);
442442
} catch (NoSuchAlgorithmException e) {
443+
SSLUtil.logSecurityRelatedException(e);
443444
throw new RuntimeException(String.format("Unable to get SSLContext instance with protocol: %s; cause: %s",
444445
sslProtocol, e.getMessage()), e);
445446
}
446447
if (userTrustManager != null) {
447448
try {
448449
sslContext.init(null, new X509TrustManager[]{userTrustManager}, null);
449450
} catch (KeyManagementException e) {
451+
SSLUtil.logSecurityRelatedException(e);
450452
throw new RuntimeException(String.format("Unable to initialize SSLContext; protocol: %s; cause: %s",
451453
sslProtocol, e.getMessage()), e);
452454
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/HTTPKerberosAuthInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public HTTPKerberosAuthInterceptor(String host, Map<String,String> krbOptions) {
4848
try {
4949
buildSubjectCredentials();
5050
} catch (LoginException e) {
51+
SSLUtil.logSecurityRelatedException(e);
5152
throw new FailedRequestException(e.getMessage(), e);
5253
}
5354
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,8 @@ private boolean getDocumentImpl(RequestLogger reqlog,
879879
"Document read for document identifier without uri");
880880
}
881881

882-
assert metadataHandle != null : "metadataHandle is null";
883-
assert contentHandle != null : "contentHandle is null";
882+
Objects.requireNonNull(metadataHandle);
883+
Objects.requireNonNull(contentHandle);
884884

885885
logger.debug("Getting multipart for {} in transaction {}", uri, getTransactionId(transaction));
886886

marklogic-client-api/src/main/java/com/marklogic/client/impl/QueryOptionsTransformInjectNS.java

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)