Why am I getting concurrent execution exception in Java?

I have a java project and I can run this project by packaging it in a jar file successfully on Windows.

When it comes to Unix, I can start the GUI and and do some stuff to run a process. At this point, I get the following error;

java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
	at java.util.concurrent.FutureTask.get(FutureTask.java:91)
	at com.some.path.RunPerl.runMwcheck(RunPerl.java:176)
	at com.some.path.ToolBarListener$1.run(ToolBarListener.java:266)
	at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
	at com.some.path.CheckRunner.call(CheckRunner.java:51)
	at com.some.path.CheckRunner.call(CheckRunner.java:1)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	... 1 more

Open in new window

Why do you think I am getting this error?
Who is Participating?
mccarlConnect With a Mentor IT Business Systems Analyst / Software DeveloperCommented:
Ah ok, so the REAL problem is around line 31. You are catching an exception that is being thrown by the .exec() call (on line 29) and you are printing an error message, but you are still allowing the execution of the code to continue. So "mtcheck_process" will still be NULL (since the call to .exec failed and no process object is returned) and then when you attempt to call .getInputStream() on mtcheck_process, the NullPointerException gets thrown.

You need to properly handle the exception at line 31, so that you don't try and continue running the code. And then you need to look at why the .exec() call is failing in the first place!
mccarlIT Business Systems Analyst / Software DeveloperCommented:
The "ExecutionException" is not really the interesting part of that stack trace. It is just being thrown as a result of the NullPointerException being thrown.

So you need to look closely at...
Caused by: java.lang.NullPointerException
      at com.some.path.CheckRunner.call(CheckRunner.java:51)
If it is not obvious, can you post your latest code for CheckRunner.java so that we can see what is on line 51?
TolgarAuthor Commented:
This is the full CheckRunner.java code: (Please see line 36 below)

public class CheckRunner implements Callable<List<CheckDetail>> {
    protected String resultsXML;
    protected String execCmd;
    static List<CheckDetail> checkDetails = null;
    final static List<CheckDetail> checkDetailsAll = new ArrayList<CheckDetail>();
    private Process mtcheck_process = null;
   public void setCommand(String perlCmd)
       execCmd = perlCmd;
   public List<CheckDetail> call() {
     //get the environment variables
       Map<String, String> env = System.getenv();
       String [] environment = new String[env.size()];
       int i = 0;
       for (Map.Entry<String, String> entry : env.entrySet())
           environment[i] = entry.getKey() + "=" + entry.getValue();
       Runtime mtcheck_runtime = Runtime.getRuntime();
       try {
           mtcheck_process = mtcheck_runtime.exec(execCmd);
       } catch (Exception e) {
           System.out.println("error executing " + execCmd);

       /* dump output stream */
       InputStream is = mtcheck_process.getInputStream();  // --> THIS IS LINE 51 IN THE ORIGINAL CODE
       BufferedReader reader = new BufferedReader
           ( new InputStreamReader(is));
       String commandLineOutput;
       try {
        while ((commandLineOutput = reader.readLine()) != null) {
               Pattern p = Pattern.compile("\\d{8}_\\d{4}_\\d{2}_.*?_Mtcheck_CodingStandards_ALL_Files.xml");
               Matcher m = p.matcher(commandLineOutput);
               if (m.find()){
                   resultsXML = m.group();                       
    } catch (IOException e) {
        // TODO Auto-generated catch block
       /* print final result of process */
       System.err.println("Exit status=" + mtcheck_process.exitValue());
       String tempDir = null;
       String OS = System.getProperty("os.name").toLowerCase();
       if (OS.indexOf("win") >= 0){
           tempDir = "C:/Temp/mtcheck";
       } else{
           tempDir = "/tmp/mtcheck";
       //get the name of the  generated XML from the CLI 
       //and parse it to generate the results table
       String path2ResultsXML = tempDir + "/" + resultsXML;
       new ParseResultsXML().parse(path2ResultsXML);
       //checkDetails = new ParseResultsXML().getResultsXMLData();
       checkDetails = new ParseResultsXML().parse(path2ResultsXML);
    //return checkDetailsAll;
       return checkDetails;

    public static List<CheckDetail> getList(){
        return checkDetailsAll;
    public static void cleanList(){
    public void stop() {
        if (mtcheck_process != null) {

Open in new window

TolgarAuthor Commented:
You were right. Now, it works on Unix too.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
That's good! :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.