Program: 91736
Project: 91736
Buggy source:
/** 
 * Perform a launch of a command in a container and output stdout/stderr to console.
 * @param id - id of caller to use to distinguish console owner
 * @param listener - optional listener of the run console
 * @param connectionUri - the specified connection to use
 * @param image - the image to use
 * @param command - command to run
 * @param commandDir - directory command requires or null
 * @param workingDir - working directory or null
 * @param additionalDirs - additional directories to mount or null
 * @param origEnv - original environment if we are appending to our existing environment
 * @param envMap - map of environment variable settings
 * @param ports - ports to expose
 * @param keep - keep container after running
 * @param stdinSupport - true if stdin support is required, false otherwise
 * @param privilegedMode - true if privileged mode is required, false otherwise
 * @param labels - Map of labels for the container
 * @param seccomp - seccomp profile
 * @since 3.0
 */
public void launch(String id,IContainerLaunchListener listener,final String connectionUri,String image,String command,String commandDir,String workingDir,List<String> additionalDirs,Map<String,String> origEnv,Map<String,String> envMap,List<String> ports,boolean keep,boolean stdinSupport,boolean privilegedMode,Map<String,String> labels,String seccomp){
  final String LAUNCH_TITLE="String_Node_Str";
  final String LAUNCH_EXITED_TITLE="String_Node_Str";
  final List<String> env=new ArrayList<>();
  env.addAll(toList(origEnv));
  env.addAll(toList(envMap));
  final List<String> cmdList=getCmdList(command);
  final Set<String> exposedPorts=new HashSet<>();
  final Map<String,List<IDockerPortBinding>> portBindingsMap=new HashMap<>();
  if (ports != null) {
    for (    String port : ports) {
      port=port.trim();
      if (port.length() > 0) {
        String[] segments=port.split("String_Node_Str");
        if (segments.length == 1) {
          exposedPorts.add(segments[0]);
          portBindingsMap.put(segments[0],Arrays.asList((IDockerPortBinding)new DockerPortBinding("String_Node_Str","String_Node_Str")));
        }
 else         if (segments.length == 2) {
          exposedPorts.add(segments[1]);
          portBindingsMap.put(segments[1],Arrays.asList((IDockerPortBinding)new DockerPortBinding("String_Node_Str",segments[0])));
        }
 else         if (segments.length == 3) {
          exposedPorts.add(segments[1]);
          if (segments[1].isEmpty()) {
            portBindingsMap.put(segments[2],Arrays.asList((IDockerPortBinding)new DockerPortBinding("String_Node_Str",segments[0])));
          }
 else {
            portBindingsMap.put(segments[2],Arrays.asList((IDockerPortBinding)new DockerPortBinding(segments[0],segments[1])));
          }
        }
      }
    }
  }
  DockerContainerConfig.Builder builder=new DockerContainerConfig.Builder().openStdin(stdinSupport).cmd(cmdList).image(image).workingDir(workingDir);
  if (listener != null && listener.getClass().getName().equals("String_Node_Str")) {
    builder=builder.tty(true);
  }
  if (exposedPorts.size() > 0)   builder=builder.exposedPorts(exposedPorts);
  if (labels != null)   builder=builder.labels(labels);
  if (!DockerConnectionManager.getInstance().hasConnections()) {
    Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DVMessages.getString(ERROR_LAUNCHING_CONTAINER),DVMessages.getString(ERROR_NO_CONNECTIONS)));
    return;
  }
  final IDockerConnection connection=DockerConnectionManager.getInstance().getConnectionByUri(connectionUri);
  if (connection == null) {
    Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DVMessages.getString(ERROR_LAUNCHING_CONTAINER),DVMessages.getFormattedString(ERROR_NO_CONNECTION_WITH_URI,connectionUri)));
    return;
  }
  if (!connection.isOpen()) {
    connection.getImages();
  }
  DockerHostConfig.Builder hostBuilder=new DockerHostConfig.Builder().privileged(privilegedMode);
  if (seccomp != null) {
    hostBuilder.securityOpt(seccomp);
  }
  final Map<String,String> remoteVolumes=new HashMap<>();
  if (!((DockerConnection)connection).isLocal()) {
    final Set<String> volumes=new HashSet<>();
    if (additionalDirs != null) {
      for (      String dir : additionalDirs) {
        remoteVolumes.put(dir,dir);
        volumes.add(dir);
      }
    }
    if (workingDir != null) {
      remoteVolumes.put(workingDir,workingDir);
      volumes.add(workingDir);
    }
    if (commandDir != null) {
      remoteVolumes.put(commandDir,commandDir);
      volumes.add(commandDir);
    }
    builder=builder.volumes(volumes);
  }
 else {
    final List<String> volumes=new ArrayList<>();
    if (additionalDirs != null) {
      for (      String dir : additionalDirs) {
        volumes.add(dir + "String_Node_Str" + dir+ "String_Node_Str");
      }
    }
    if (workingDir != null) {
      volumes.add(workingDir + "String_Node_Str" + workingDir+ "String_Node_Str");
    }
    if (commandDir != null) {
      volumes.add(commandDir + "String_Node_Str" + commandDir+ "String_Node_Str");
    }
    hostBuilder=hostBuilder.binds(volumes);
  }
  final DockerContainerConfig config=builder.build();
  if (portBindingsMap.size() > 0)   hostBuilder=hostBuilder.portBindings(portBindingsMap);
  final IDockerHostConfig hostConfig=hostBuilder.build();
  final String imageName=image;
  final boolean keepContainer=keep;
  final String consoleId=id;
  final IContainerLaunchListener containerListener=listener;
  Thread t=new Thread(() -> {
    String containerId=null;
    try {
      containerId=((DockerConnection)connection).createContainer(config,hostConfig,null);
      if (!((DockerConnection)connection).isLocal()) {
        if (!remoteVolumes.isEmpty()) {
          CopyVolumesJob job=new CopyVolumesJob(remoteVolumes,connection,containerId);
          job.schedule();
          job.join();
          if (job.getResult() != Status.OK_STATUS)           return;
        }
      }
      if (config.tty()) {
        OutputStream stream=null;
        RunConsole oldConsole=getConsole();
        final RunConsole rc=RunConsole.findConsole(containerId,consoleId);
        setConsole(rc);
        rc.clearConsole();
        if (oldConsole != null)         RunConsole.removeConsole(oldConsole);
        Display.getDefault().syncExec(() -> rc.setTitle(Messages.getFormattedString(LAUNCH_TITLE,new String[]{cmdList.get(0),imageName})));
        if (rc != null) {
          stream=rc.getOutputStream();
        }
        DockerConsoleOutputStream out=new DockerConsoleOutputStream(stream);
        RunConsole.attachToTerminal(connection,containerId,out);
        if (containerListener != null) {
          out.addConsoleListener(new RunConsoleListenerBridge(containerListener));
        }
        ((DockerConnection)connection).startContainer(containerId,null,null);
        IDockerContainerInfo info=((DockerConnection)connection).getContainerInfo(containerId);
        if (containerListener != null) {
          containerListener.containerInfo(info);
        }
        final IDockerContainerExit status=((DockerConnection)connection).waitForContainer(containerId);
        Display.getDefault().syncExec(() -> {
          rc.setTitle(Messages.getFormattedString(LAUNCH_EXITED_TITLE,new String[]{status.statusCode().toString(),cmdList.get(0),imageName}));
          rc.showConsole();
          IWorkbenchPage page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
          IViewPart terminalView=page.findView("String_Node_Str");
          CTabFolder ctabfolder=terminalView.getAdapter(CTabFolder.class);
          if (ctabfolder != null) {
            CTabItem[] items=ctabfolder.getItems();
            for (            CTabItem item : items) {
              if (item.getText().endsWith(info.name())) {
                item.dispose();
                break;
              }
            }
          }
        }
);
        if (containerListener != null)         containerListener.done();
        if (!keepContainer) {
          ((DockerConnection)connection).removeContainer(containerId);
        }
      }
 else {
        OutputStream stream=null;
        RunConsole oldConsole=getConsole();
        final RunConsole rc=RunConsole.findConsole(containerId,consoleId);
        setConsole(rc);
        rc.clearConsole();
        if (oldConsole != null)         RunConsole.removeConsole(oldConsole);
        Display.getDefault().syncExec(() -> rc.setTitle(Messages.getFormattedString(LAUNCH_TITLE,new String[]{cmdList.get(0),imageName})));
        rc.attachToConsole(connection,containerId);
        if (rc != null) {
          stream=rc.getOutputStream();
          if (containerListener != null) {
            ((ConsoleOutputStream)stream).addConsoleListener(containerListener);
          }
        }
        String loggingId=containerId + "String_Node_Str" + consoleId;
        ((DockerConnection)connection).startContainer(containerId,loggingId,stream);
        if (rc != null)         rc.showConsole();
        if (containerListener != null) {
          IDockerContainerInfo info=((DockerConnection)connection).getContainerInfo(containerId);
          containerListener.containerInfo(info);
        }
        final IDockerContainerExit status=((DockerConnection)connection).waitForContainer(containerId);
        Display.getDefault().syncExec(() -> {
          rc.setTitle(Messages.getFormattedString(LAUNCH_EXITED_TITLE,new String[]{status.statusCode().toString(),cmdList.get(0),imageName}));
          rc.showConsole();
        }
);
        if (containerListener != null)         containerListener.done();
        if (!keepContainer) {
          Thread.sleep(1000);
          ((DockerConnection)connection).stopLoggingThread(loggingId);
          RunConsole rc2=RunConsole.findConsole(((DockerConnection)connection).getContainer(containerId));
          if (rc2 != null)           RunConsole.removeConsole(rc2);
          ((DockerConnection)connection).removeContainer(containerId);
        }
      }
    }
 catch (    final DockerException e2) {
      if (!keepContainer && containerId != null) {
        try {
          ((DockerConnection)connection).removeContainer(containerId);
        }
 catch (        DockerException|InterruptedException e1) {
        }
      }
      Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DVMessages.getFormattedString(ERROR_CREATING_CONTAINER,imageName),e2.getMessage()));
    }
catch (    InterruptedException e3) {
    }
    ((DockerConnection)connection).getContainers(true);
  }
);
  t.start();
}

Fixed version (ground truth):
/** 
 * Perform a launch of a command in a container and output stdout/stderr to console.
 * @param id - id of caller to use to distinguish console owner
 * @param listener - optional listener of the run console
 * @param connectionUri - the specified connection to use
 * @param image - the image to use
 * @param cmdList - command to run as list of String
 * @param workingDir - working directory or null
 * @param additionalDirs - additional directories to mount or null
 * @param origEnv - original environment if we are appending to our existing environment
 * @param envMap - map of environment variable settings
 * @param ports - ports to expose
 * @param keep - keep container after running
 * @param stdinSupport - true if stdin support is required, false otherwise
 * @param privilegedMode - true if privileged mode is required, false otherwise
 * @param labels - Map of labels for the container
 * @param seccomp - seccomp profile
 * @since 4.0
 */
public void launch(String id,IContainerLaunchListener listener,final String connectionUri,String image,List<String> cmdList,String workingDir,List<String> additionalDirs,Map<String,String> origEnv,Map<String,String> envMap,List<String> ports,boolean keep,boolean stdinSupport,boolean privilegedMode,Map<String,String> labels,String seccomp){
  final String LAUNCH_TITLE="String_Node_Str";
  final String LAUNCH_EXITED_TITLE="String_Node_Str";
  final List<String> env=new ArrayList<>();
  env.addAll(toList(origEnv));
  env.addAll(toList(envMap));
  final Set<String> exposedPorts=new HashSet<>();
  final Map<String,List<IDockerPortBinding>> portBindingsMap=new HashMap<>();
  if (ports != null) {
    for (    String port : ports) {
      port=port.trim();
      if (port.length() > 0) {
        String[] segments=port.split("String_Node_Str");
        if (segments.length == 1) {
          exposedPorts.add(segments[0]);
          portBindingsMap.put(segments[0],Arrays.asList((IDockerPortBinding)new DockerPortBinding("String_Node_Str","String_Node_Str")));
        }
 else         if (segments.length == 2) {
          exposedPorts.add(segments[1]);
          portBindingsMap.put(segments[1],Arrays.asList((IDockerPortBinding)new DockerPortBinding("String_Node_Str",segments[0])));
        }
 else         if (segments.length == 3) {
          exposedPorts.add(segments[1]);
          if (segments[1].isEmpty()) {
            portBindingsMap.put(segments[2],Arrays.asList((IDockerPortBinding)new DockerPortBinding("String_Node_Str",segments[0])));
          }
 else {
            portBindingsMap.put(segments[2],Arrays.asList((IDockerPortBinding)new DockerPortBinding(segments[0],segments[1])));
          }
        }
      }
    }
  }
  DockerContainerConfig.Builder builder=new DockerContainerConfig.Builder().openStdin(stdinSupport).cmd(cmdList).image(image).workingDir(workingDir);
  if (listener != null && listener.getClass().getName().equals("String_Node_Str")) {
    builder=builder.tty(true);
  }
  if (exposedPorts.size() > 0)   builder=builder.exposedPorts(exposedPorts);
  if (labels != null)   builder=builder.labels(labels);
  if (!DockerConnectionManager.getInstance().hasConnections()) {
    Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DVMessages.getString(ERROR_LAUNCHING_CONTAINER),DVMessages.getString(ERROR_NO_CONNECTIONS)));
    return;
  }
  final IDockerConnection connection=DockerConnectionManager.getInstance().getConnectionByUri(connectionUri);
  if (connection == null) {
    Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DVMessages.getString(ERROR_LAUNCHING_CONTAINER),DVMessages.getFormattedString(ERROR_NO_CONNECTION_WITH_URI,connectionUri)));
    return;
  }
  if (!connection.isOpen()) {
    connection.getImages();
  }
  DockerHostConfig.Builder hostBuilder=new DockerHostConfig.Builder().privileged(privilegedMode);
  if (seccomp != null) {
    hostBuilder.securityOpt(seccomp);
  }
  final Map<String,String> remoteVolumes=new HashMap<>();
  if (!((DockerConnection)connection).isLocal()) {
    final Set<String> volumes=new HashSet<>();
    if (additionalDirs != null) {
      for (      String dir : additionalDirs) {
        remoteVolumes.put(dir,dir);
        volumes.add(dir);
      }
    }
    if (workingDir != null) {
      remoteVolumes.put(workingDir,workingDir);
      volumes.add(workingDir);
    }
    builder=builder.volumes(volumes);
  }
 else {
    final List<String> volumes=new ArrayList<>();
    if (additionalDirs != null) {
      for (      String dir : additionalDirs) {
        volumes.add(dir + "String_Node_Str" + dir+ "String_Node_Str");
      }
    }
    if (workingDir != null) {
      volumes.add(workingDir + "String_Node_Str" + workingDir+ "String_Node_Str");
    }
    hostBuilder=hostBuilder.binds(volumes);
  }
  final DockerContainerConfig config=builder.build();
  if (portBindingsMap.size() > 0)   hostBuilder=hostBuilder.portBindings(portBindingsMap);
  final IDockerHostConfig hostConfig=hostBuilder.build();
  final String imageName=image;
  final boolean keepContainer=keep;
  final String consoleId=id;
  final IContainerLaunchListener containerListener=listener;
  Thread t=new Thread(() -> {
    String containerId=null;
    try {
      containerId=((DockerConnection)connection).createContainer(config,hostConfig,null);
      if (!((DockerConnection)connection).isLocal()) {
        if (!remoteVolumes.isEmpty()) {
          CopyVolumesJob job=new CopyVolumesJob(remoteVolumes,connection,containerId);
          job.schedule();
          job.join();
          if (job.getResult() != Status.OK_STATUS)           return;
        }
      }
      if (config.tty()) {
        OutputStream stream=null;
        RunConsole oldConsole=getConsole();
        final RunConsole rc=RunConsole.findConsole(containerId,consoleId);
        setConsole(rc);
        rc.clearConsole();
        if (oldConsole != null)         RunConsole.removeConsole(oldConsole);
        Display.getDefault().syncExec(() -> rc.setTitle(Messages.getFormattedString(LAUNCH_TITLE,new String[]{cmdList.get(0),imageName})));
        if (rc != null) {
          stream=rc.getOutputStream();
        }
        DockerConsoleOutputStream out=new DockerConsoleOutputStream(stream);
        RunConsole.attachToTerminal(connection,containerId,out);
        if (containerListener != null) {
          out.addConsoleListener(new RunConsoleListenerBridge(containerListener));
        }
        ((DockerConnection)connection).startContainer(containerId,null,null);
        IDockerContainerInfo info=((DockerConnection)connection).getContainerInfo(containerId);
        if (containerListener != null) {
          containerListener.containerInfo(info);
        }
        final IDockerContainerExit status=((DockerConnection)connection).waitForContainer(containerId);
        Display.getDefault().syncExec(() -> {
          rc.setTitle(Messages.getFormattedString(LAUNCH_EXITED_TITLE,new String[]{status.statusCode().toString(),cmdList.get(0),imageName}));
          rc.showConsole();
          IWorkbenchPage page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
          IViewPart terminalView=page.findView("String_Node_Str");
          CTabFolder ctabfolder=terminalView.getAdapter(CTabFolder.class);
          if (ctabfolder != null) {
            CTabItem[] items=ctabfolder.getItems();
            for (            CTabItem item : items) {
              if (item.getText().endsWith(info.name())) {
                item.dispose();
                break;
              }
            }
          }
        }
);
        if (containerListener != null)         containerListener.done();
        if (!keepContainer) {
          ((DockerConnection)connection).removeContainer(containerId);
        }
      }
 else {
        OutputStream stream=null;
        RunConsole oldConsole=getConsole();
        final RunConsole rc=RunConsole.findConsole(containerId,consoleId);
        setConsole(rc);
        rc.clearConsole();
        if (oldConsole != null)         RunConsole.removeConsole(oldConsole);
        Display.getDefault().syncExec(() -> rc.setTitle(Messages.getFormattedString(LAUNCH_TITLE,new String[]{cmdList.get(0),imageName})));
        rc.attachToConsole(connection,containerId);
        if (rc != null) {
          stream=rc.getOutputStream();
          if (containerListener != null) {
            ((ConsoleOutputStream)stream).addConsoleListener(containerListener);
          }
        }
        String loggingId=containerId + "String_Node_Str" + consoleId;
        ((DockerConnection)connection).startContainer(containerId,loggingId,stream);
        if (rc != null)         rc.showConsole();
        if (containerListener != null) {
          IDockerContainerInfo info=((DockerConnection)connection).getContainerInfo(containerId);
          containerListener.containerInfo(info);
        }
        final IDockerContainerExit status=((DockerConnection)connection).waitForContainer(containerId);
        Display.getDefault().syncExec(() -> {
          rc.setTitle(Messages.getFormattedString(LAUNCH_EXITED_TITLE,new String[]{status.statusCode().toString(),cmdList.get(0),imageName}));
          rc.showConsole();
        }
);
        if (containerListener != null)         containerListener.done();
        if (!keepContainer) {
          Thread.sleep(1000);
          ((DockerConnection)connection).stopLoggingThread(loggingId);
          RunConsole rc2=RunConsole.findConsole(((DockerConnection)connection).getContainer(containerId));
          if (rc2 != null)           RunConsole.removeConsole(rc2);
          ((DockerConnection)connection).removeContainer(containerId);
        }
      }
    }
 catch (    final DockerException e2) {
      if (!keepContainer && containerId != null) {
        try {
          ((DockerConnection)connection).removeContainer(containerId);
        }
 catch (        DockerException|InterruptedException e1) {
        }
      }
      Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DVMessages.getFormattedString(ERROR_CREATING_CONTAINER,imageName),e2.getMessage()));
    }
catch (    InterruptedException e3) {
    }
    ((DockerConnection)connection).getContainers(true);
  }
);
  t.start();
}