You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2018/04/25 21:18:27 UTC

[airavata] branch staging updated: Fixing possible NPE when publishing process status

This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch staging
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/staging by this push:
     new aea2b55  Fixing possible NPE when publishing process status
aea2b55 is described below

commit aea2b55231eedd228474a2437b1eb7953ee833c6
Author: dimuthu <di...@gmail.com>
AuthorDate: Wed Apr 25 17:18:18 2018 -0400

    Fixing possible NPE when publishing process status
---
 .../airavata/helix/impl/task/AiravataTask.java       | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/AiravataTask.java b/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/AiravataTask.java
index 6dc26e1..6006351 100644
--- a/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/AiravataTask.java
+++ b/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/AiravataTask.java
@@ -50,7 +50,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 
-import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Collections;
 import java.util.List;
@@ -105,7 +104,11 @@ public abstract class AiravataTask extends AbstractTask {
         logger.error(errorMessage, error);
 
         status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
-        getTaskContext().setProcessStatus(status);
+        if (getTaskContext() != null) { // task context could be null if the initialization failed
+            getTaskContext().setProcessStatus(status);
+        } else {
+            logger.warn("Task context is null. So can not store the process status in the context");
+        }
 
         ErrorModel errorModel = new ErrorModel();
         errorModel.setUserFriendlyMessage(reason);
@@ -114,7 +117,7 @@ public abstract class AiravataTask extends AbstractTask {
 
         if (!skipTaskStatusPublish) {
             publishTaskState(TaskState.FAILED);
-            saveAndPublishProcessStatus();
+            saveAndPublishProcessStatus(taskContext != null ? taskContext.getProcessStatus() : status);
             saveExperimentError(errorModel);
             saveProcessError(errorModel);
             saveTaskError(errorModel);
@@ -126,14 +129,17 @@ public abstract class AiravataTask extends AbstractTask {
     protected void saveAndPublishProcessStatus(ProcessState state) {
         ProcessStatus processStatus = new ProcessStatus(state);
         processStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
-        getTaskContext().setProcessStatus(processStatus);
-        saveAndPublishProcessStatus();
+        if (getTaskContext() != null) {
+            getTaskContext().setProcessStatus(processStatus);
+        } else {
+            logger.warn("Task context is null. So can not store the process status in the context");
+        }
+        saveAndPublishProcessStatus((taskContext != null ? taskContext.getProcessStatus() : processStatus));
     }
 
     @SuppressWarnings("WeakerAccess")
-    protected void saveAndPublishProcessStatus() {
+    protected void saveAndPublishProcessStatus(ProcessStatus status) {
         try {
-            ProcessStatus status = taskContext.getProcessStatus();
             if (status.getTimeOfStateChange() == 0 || status.getTimeOfStateChange() > 0 ){
                 status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
             } else {

-- 
To stop receiving notification emails like this one, please contact
dimuthuupe@apache.org.