Skip to content

Commit f3517b0

Browse files
authored
Merge pull request #737 from marklogic/feature/21542-polaris-nulls
MLE-21542 First batch of null checks
2 parents 641ba98 + cb2dd17 commit f3517b0

37 files changed

+192
-113
lines changed

ml-app-deployer/src/main/java/com/marklogic/appdeployer/ConfigDir.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public List<File> getDatabaseResourceDirectories() {
7171
File dbDir = getDatabasesDir();
7272
if (dbDir != null && dbDir.exists()) {
7373
File[] dirs = dbDir.listFiles(pathname -> pathname.isDirectory());
74-
return Arrays.asList(dirs);
74+
if (dirs != null) {
75+
return Arrays.asList(dirs);
76+
}
7577
}
7678
return new ArrayList<>();
7779
}

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractResourceCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ public void execute(CommandContext context) {
5555
setIncrementalMode(isIncrementalDeploy);
5656
}
5757

58-
for (File resourceDir : getResourceDirs(context)) {
59-
processExecuteOnResourceDir(context, resourceDir);
58+
File[] dirs = getResourceDirs(context);
59+
if (dirs != null) {
60+
for (File resourceDir : dirs) {
61+
processExecuteOnResourceDir(context, resourceDir);
62+
}
6063
}
6164

6265
if (mergeResourcesBeforeSaving) {

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/admin/RequireAtLeastMl8Command.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public void execute(CommandContext context) {
3333
if (logger.isInfoEnabled()) {
3434
logger.info("Verifying MarkLogic version is at least 8 or higher; version: " + version);
3535
}
36-
major = Integer.parseInt(version.split("\\.")[0]);
36+
if (version != null) {
37+
major = Integer.parseInt(version.split("\\.")[0]);
38+
}
3739
} catch (Exception e) {
3840
logger.warn("Unable to verify MarkLogic version is 8 or higher, will continue with deployment; error: "
3941
+ e.getMessage());

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/alert/DeployAlertActionsCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ public void execute(CommandContext context) {
6060
protected void deployActions(CommandContext context, ConfigDir configDir, String databaseIdOrName) {
6161
File configsDir = configDir.getAlertConfigsDir();
6262
if (configsDir != null && configsDir.exists()) {
63-
for (File f : configsDir.listFiles()) {
64-
if (f.isDirectory() && f.getName().endsWith(actionsDirectorySuffix)) {
65-
deployActionsInDirectory(f, context, databaseIdOrName);
63+
File[] files = configsDir.listFiles();
64+
if (files != null) {
65+
for (File f : files) {
66+
if (f.isDirectory() && f.getName().endsWith(actionsDirectorySuffix)) {
67+
deployActionsInDirectory(f, context, databaseIdOrName);
68+
}
6669
}
6770
}
6871
} else {

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/alert/DeployAlertRulesCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ public void execute(CommandContext context) {
5151
protected void deployRules(CommandContext context, ConfigDir configDir, String databaseIdOrName) {
5252
File configsDir = configDir.getAlertConfigsDir();
5353
if (configsDir != null && configsDir.exists()) {
54-
for (File f : configsDir.listFiles()) {
55-
if (f.isDirectory() && f.getName().endsWith(rulesDirectorySuffix)) {
56-
deployRulesInDirectory(f, context, databaseIdOrName);
54+
File[] files = configsDir.listFiles();
55+
if (files != null) {
56+
for (File f : files) {
57+
if (f.isDirectory() && f.getName().endsWith(rulesDirectorySuffix)) {
58+
deployRulesInDirectory(f, context, databaseIdOrName);
59+
}
5760
}
5861
}
5962
} else {

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/clusters/ModifyLocalClusterCommand.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ public void execute(CommandContext context) {
3939
for (ConfigDir configDir : context.getAppConfig().getConfigDirs()) {
4040
File clustersDir = configDir.getClustersDir();
4141
if (clustersDir != null && clustersDir.exists()) {
42-
for (File f : clustersDir.listFiles()) {
43-
if (f.isFile() && f.getName().startsWith("local-cluster")) {
44-
String payload = copyFileToString(f, context);
45-
new ClusterManager(context.getManageClient()).modifyLocalCluster(payload, context.getAdminManager());
42+
File[] files = clustersDir.listFiles();
43+
if (files != null) {
44+
for (File f : files) {
45+
if (f.isFile() && f.getName().startsWith("local-cluster")) {
46+
String payload = copyFileToString(f, context);
47+
new ClusterManager(context.getManageClient()).modifyLocalCluster(payload, context.getAdminManager());
48+
}
4649
}
4750
}
4851
} else {

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/databases/DeployDatabaseCommand.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,16 @@ public String buildPayloadForSaving(CommandContext context) {
188188
@Override
189189
public void undo(CommandContext context) {
190190
String payload = buildPayload(context);
191-
192-
if (databasesToNotUndeploy != null) {
193-
final String dbName = new PayloadParser().getPayloadFieldValue(payload, "database-name", false);
194-
if (dbName != null && databasesToNotUndeploy.contains(dbName)) {
195-
logger.info(format("Not undeploying database %s because it is in the list of database names to not undeploy.", dbName));
196-
return;
197-
}
198-
}
199-
200191
if (payload != null) {
201-
DatabaseManager dbMgr = newDatabaseManageForDeleting(context);
192+
if (databasesToNotUndeploy != null) {
193+
final String dbName = new PayloadParser().getPayloadFieldValue(payload, "database-name", false);
194+
if (dbName != null && databasesToNotUndeploy.contains(dbName)) {
195+
logger.info(format("Not undeploying database %s because it is in the list of database names to not undeploy.", dbName));
196+
return;
197+
}
198+
}
199+
200+
DatabaseManager dbMgr = newDatabaseManageForDeleting(context);
202201

203202
// if this has sub-databases, detach/delete them first
204203
if (!isSubDatabase()) {

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/databases/DeployOtherDatabasesCommand.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ protected List<DatabasePlan> mergeDatabasePlanFiles(CommandContext context, Data
295295
nodes.add(convertPayloadToObjectNode(context, payload));
296296
});
297297
ObjectNode mergedNode = JsonNodeUtil.mergeObjectNodes(nodes.toArray(new ObjectNode[]{}));
298+
Objects.requireNonNull(mergedNode);
298299
reference.setMergedObjectNode(mergedNode);
299300
try {
300301
reference.setDatabaseForSorting(objectReader.readValue(mergedNode));
@@ -398,11 +399,12 @@ protected void deployDatabasesAndForestsViaCma(CommandContext context, List<Data
398399
databasePlans.forEach(plan -> {
399400
final DeployDatabaseCommand deployDatabaseCommand = plan.getDeployDatabaseCommand();
400401
String payload = deployDatabaseCommand.buildPayloadForSaving(context);
401-
dbConfig.addDatabase(convertPayloadToObjectNode(context, payload));
402-
403-
DeployForestsCommand deployForestsCommand = deployDatabaseCommand.buildDeployForestsCommand(plan.getDatabaseName(), context);
404-
if (deployForestsCommand != null) {
405-
deployForestsCommand.buildForests(context, false).forEach(forest -> forestConfig.addForest(forest.toObjectNode()));
402+
if (payload != null) {
403+
dbConfig.addDatabase(convertPayloadToObjectNode(context, payload));
404+
DeployForestsCommand deployForestsCommand = deployDatabaseCommand.buildDeployForestsCommand(plan.getDatabaseName(), context);
405+
if (deployForestsCommand != null) {
406+
deployForestsCommand.buildForests(context, false).forEach(forest -> forestConfig.addForest(forest.toObjectNode()));
407+
}
406408
}
407409
});
408410

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/flexrep/DeployTargetsCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ public void execute(CommandContext context) {
5858
protected void deployTargets(CommandContext context, ConfigDir configDir, String databaseIdOrName) {
5959
File configsDir = configDir.getFlexrepConfigsDir();
6060
if (configsDir != null && configsDir.exists()) {
61-
for (File f : configsDir.listFiles()) {
62-
if (f.isDirectory() && f.getName().endsWith(targetDirectorySuffix)) {
63-
deployTargetsInDirectory(f, context, databaseIdOrName);
61+
File[] files = configsDir.listFiles();
62+
if (files != null) {
63+
for (File f : files) {
64+
if (f.isDirectory() && f.getName().endsWith(targetDirectorySuffix)) {
65+
deployTargetsInDirectory(f, context, databaseIdOrName);
66+
}
6467
}
6568
}
6669
} else {

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/forests/DeployCustomForestsCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ public void execute(CommandContext context) {
5353
File dir = new File(configDir.getBaseDir(), customForestsPath);
5454
if (dir != null && dir.exists()) {
5555
payloadParser = new PayloadParser();
56-
for (File f : dir.listFiles()) {
57-
if (f.isDirectory()) {
58-
processDirectory(f, context);
56+
File[] dirs = dir.listFiles();
57+
if (dirs != null) {
58+
for (File f : dirs) {
59+
if (f.isDirectory()) {
60+
processDirectory(f, context);
61+
}
5962
}
6063
}
6164
} else {

0 commit comments

Comments
 (0)