java.util.concurrent.ExecutionException: java.lang.NullPointerException Error

Srii picture Srii · Oct 7, 2013 · Viewed 38.9k times · Source

The following code snippet doesnt throw any error when executed in a standalone mode. When I deploy this into a web server [implementing a server's interface and added as JAR into classpath], I get

 java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.nbis.process.JSON_2_File_Split_V004.fn_1_parserEntity(JSON_2_File_Split_V004.java:256)
at com.nbis.process.JSON_2_File_Split_V004.fn_0_primaryCaller(JSON_2_File_Split_V004.java:177)
at com.nbis.process.JSON_2_File_Split_V004.execute(JSON_2_File_Split_V004.java:151)

Code Snippet:

this.callable = new JSON_3_File_Process_V005(this.originalFileName, this.inProgressDirLoc, this.processedDirLoc, "[" + jSONRecord.toString() + "]", this.dataMDHolder, this.dataAccIDValueMap, this.dataCountryNameValueMap);
String[] fullContent = null;    
try {
    fullContent = executor.submit(this.callable).get();
} catch (ExecutionException e) {
    StringWriter errors = new StringWriter();
    e.printStackTrace(new PrintWriter(errors));
    log.info("Srii: " + errors.toString());
    executor.shutdown();
    return 7;
    } 

Adding the get's return value to an ExecutorCompletionService would be an option, but would that not kill the concept of asynchronous processing? In other words, I collect in StringBuilder the output string from callable get and store to a disk when the get count reaches a specific number. Once data is emitted to disk, I refresh the StringBuilder. This way I push data to a disk at regular intervals without having to keep them in memory.

Any suggestions as to what wrong am I doing here? Appreciate any inputs. Thank you.

Answer

Srii picture Srii · Oct 8, 2013

This is fixed. If it could useful:

The problem was with the way the variables were declared. I had to declare a class-level variable as static so the any changes applied to this one started reflecting everywhere else. Strangely enough, I dint see the problem when it was executed stand-alone.

EDIT on 13112019: Moving my comment to the answer section, on request:

As its quite long time back, I dont recollect exactly the variable details. But I believe it is one of the following: this.originalFileName, this.inProgressDirLoc, this.processedDirLoc , this.dataMDHolder, this.dataAccIDValueMap, this.dataCountryNameValueMap I had to set them as static as values assigned [or modified] by any of the member was not reflecting during references of the variable within the class.