[Demonstration 1]

[Buggy Method]
@SuppressWarnings("restriction")
protected void internalAttach(final Object context, final IPropertiesContainer data, final IProgressMonitor monitor, final ICallback callback) {
    //$NON-NLS-1$
    Assert.isTrue(!Protocol.isDispatchThread(), "Illegal Thread Access");
    Assert.isNotNull(context);
    Assert.isNotNull(data);
    Assert.isNotNull(callback);
    if (context instanceof IModelNode) {
        ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(ILaunchTypes.ATTACH);
        try {
            ILaunchSelection launchSelection = new LaunchSelection(ILaunchManager.DEBUG_MODE, new RemoteSelectionContext((IModelNode) context, true));
            ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(launchConfigType, ILaunchManager.DEBUG_MODE);
            if (delegate != null) {
                // create an empty launch configuration specification to initialize all attributes with their default defaults.
                ILaunchSpecification launchSpec = delegate.getLaunchSpecification(launchConfigType.getIdentifier(), launchSelection);
                for (String key : data.getProperties().keySet()) {
                    launchSpec.addAttribute(key, data.getProperty(key));
                }
                delegate.validate(launchSpec);
                if (launchSpec != null && launchSpec.isValid()) {
                    ILaunchConfiguration[] launchConfigs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(launchConfigType);
                    launchConfigs = delegate.getMatchingLaunchConfigurations(launchSpec, launchConfigs);
                    ILaunchConfiguration config = launchConfigs != null && launchConfigs.length > 0 ? launchConfigs[0] : null;
                    boolean skip = false;
                    ILaunch activeLaunch = null;
                    if (config != null) {
                        ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
                        for (ILaunch launch : launches) {
                            if (launch.getLaunchConfiguration().getType().getIdentifier().equals(ILaunchTypes.ATTACH) && !launch.isTerminated()) {
                                IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launch.getLaunchConfiguration());
                                if (contexts != null && contexts.length == 1 && contexts[0].equals(context)) {
                                    //$NON-NLS-1$
                                    callback.setProperty("launch", launch);
                                    activeLaunch = launch;
                                    skip = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!skip) {
                        final ILaunchConfiguration finConfig = LaunchManager.getInstance().createOrUpdateLaunchConfiguration(config, launchSpec);
                        delegate.validate(ILaunchManager.DEBUG_MODE, finConfig);
                        final ILaunchListener listener = new ILaunchListener() {

                            @Override
                            public void launchAdded(ILaunch launch) {
                                if (launch != null && finConfig.equals(launch.getLaunchConfiguration())) {
                                    DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
                                    //$NON-NLS-1$
                                    callback.setProperty("launch", launch);
                                    if (launch instanceof Launch) {
                                        ((Launch) launch).setCallback(callback);
                                    } else {
                                        callback.done(this, Status.OK_STATUS);
                                    }
                                }
                            }

                            @Override
                            public void launchChanged(ILaunch launch) {
                            }

                            @Override
                            public void launchRemoved(ILaunch launch) {
                            }
                        };
                        DebugPlugin.getDefault().getLaunchManager().addLaunchListener(listener);
                        // DebugUITools.launch(...) must be called from within the UI thread.
                        DisplayUtil.safeAsyncExec(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    DebugUITools.buildAndLaunch(finConfig, ILaunchManager.DEBUG_MODE, monitor != null ? monitor : new NullProgressMonitor());
                                } catch (Exception e) {
                                    callback.done(DebugService.this, StatusHelper.getStatus(e));
                                }
                            }
                        });
                    } else {
                        org.eclipse.debug.internal.ui.DebugUIPlugin.getDefault().getPerspectiveManager().launchAdded(activeLaunch);
                        callback.done(this, Status.OK_STATUS);
                    }
                }
            }
        } catch (Exception e) {
            callback.done(this, StatusHelper.getStatus(e));
        }
    } else {
        callback.done(this, Status.OK_STATUS);
    }
}

[Buggy Hunk]
if (launch.getLaunchConfiguration().getType().getIdentifier().equals(ILaunchTypes.ATTACH) && !launch.isTerminated()) {

[Patch]
if (launch.getLaunchConfiguration() != null && launch.getLaunchConfiguration().getType().getIdentifier().equals(ILaunchTypes.ATTACH) && !launch.isTerminated()) {

[Demonstration 2]

[Buggy Method]
@Override
public void addHttpHandler(HttpServer httpServer) {
    httpServer.requestHandler(request -> {
        // log.info("Request received with path : " + request.path());
        String[] items = request.path().substring(1).split("/");
        // log.info("Request received with splited items : " + Arrays.toString(items));
        String appPath = items.length == 0 ? "" : items[0];
        if (appPath.endsWith(".js") || appPath.endsWith(".css") || appPath.endsWith(".ico") || appPath.endsWith(".jpg") || appPath.endsWith(".png"))
            appPath = "";
        // log.info("Request received with application path : /" + appPath);
        PersistentApplication application = apps.get("/" + appPath);
        if (application == null) {
            request.response().end("No application is configured with path : /" + appPath);
            throw new IllegalStateException("Unable to load an application with path : /" + appPath);
        }
        // log.info("Request detected for application : " + application.getApplicationClass().getName());
        String resourceToServe = request.path().substring(appPath.length() + 1);
        // log.info("Resource to serve : " + resourceToServe);
        if ("".equals(resourceToServe)) {
            String indexHtml = "<!DOCTYPE html>";
            indexHtml += "<html>";
            indexHtml += "<head>";
            indexHtml += "<meta charset=\"UTF-8\">";
            indexHtml += "<LINK rel=stylesheet type=\"text/css\" href=\"" + (appPath.isEmpty() ? "" : ("/" + appPath)) + "/" + application.getApplicationClass().getSimpleName().toLowerCase() + ".css\"/>";
            indexHtml += "<script>";
            indexHtml += "var serviceLocation = \"ws://\" + document.location.host + \"" + request.path() + "\";";
            indexHtml += "</script>";
            indexHtml += "<script type=\"text/javascript\" src=\"" + (appPath.isEmpty() ? "" : ("/" + appPath)) + "/" + application.getApplicationClass().getSimpleName().toLowerCase() + ".js\"></script>";
            indexHtml += "</head>";
            indexHtml += "<body onload=\"connect();\" id=\"root\">";
            indexHtml += "</body>";
            indexHtml += "</html>";
            request.response().end(indexHtml);
        } else {
            InputStream input = application.getApplicationClass().getResourceAsStream(resourceToServe);
            if (input == null) {
                if (resourceToServe.endsWith(".css")) {
                    log.warn("Unable to find resource : " + resourceToServe + ", get the reactor standard css instead");
                    input = ApplicationServer.class.getResourceAsStream("/reactor.css");
                } else if (resourceToServe.endsWith(".js")) {
                    log.warn("Unable to find resource : " + resourceToServe + ", get the reactor standard js instead");
                    input = ApplicationServer.class.getResourceAsStream("/script.js");
                } else if (resourceToServe.endsWith(".ico") || resourceToServe.endsWith(".jpg") || resourceToServe.endsWith(".png")) {
                    log.warn("Unable to find resource : " + resourceToServe + ", get nothing instead");
                    request.response().end();
                    return;
                } else
                    throw new IllegalStateException("Unable to find resource : " + resourceToServe);
            }
            String result = new BufferedReader(new InputStreamReader(input)).lines().collect(Collectors.joining("\n"));
            request.response().end(result);
        }
    });
}

[Buggy Hunk]
InputStream input = application.getApplicationClass().getResourceAsStream(resourceToServe);

[Patch]
InputStream input = application.getApplicationClass().getResourceAsStream("/" + resourceToServe);

[Demonstration 3]

[Buggy Method]
public static void main(String[] args) {
    Application.launch(args);
}

[Buggy Hunk]
Application.launch(args);

[Patch]
Application.launch(RulerWindow.class, args);