[Demonstration 1]

[Buggy Method]
@Override
public String coordinateJob(@Valid @NotNull(message = "No job request provided. Unable to submit job for execution.") final JobRequest jobRequest, @Valid @NotNull(message = "No job metadata provided. Unable to submit job for execution.") final JobMetadata jobMetadata) throws GenieException {
    final long coordinationStart = System.nanoTime();
    final String jobId = jobRequest.getId().orElseThrow(() -> new GenieServerException("Id of the jobRequest cannot be null"));
    JobStatus jobStatus = JobStatus.FAILED;
    try {
        log.info("Called to schedule job launch for job {}", jobId);
        // create the job object in the database with status INIT
        final Job.Builder jobBuilder = new Job.Builder(jobRequest.getName(), jobRequest.getUser(), jobRequest.getVersion(), jobRequest.getCommandArgs()).withId(jobId).withTags(jobRequest.getTags()).withStatus(JobStatus.INIT).withStatusMsg("Job Accepted and in initialization phase.");
        jobRequest.getDescription().ifPresent(jobBuilder::withDescription);
        if (!jobRequest.isDisableLogArchival()) {
            jobBuilder.withArchiveLocation(this.jobsProperties.getLocations().getArchives() + JobConstants.FILE_PATH_DELIMITER + jobId + ".tar.gz");
        }
        final JobExecution jobExecution = new JobExecution.Builder(this.hostName).withId(jobId).build();
        // Log all the job initial job information
        this.jobPersistenceService.createJob(jobRequest, jobMetadata, jobBuilder.build(), jobExecution);
        jobStateService.init(jobId);
        //TODO: Combine the cluster and command selection into a single method/database query for efficiency
        // Resolve the cluster for the job request based on the tags specified
        final Cluster cluster = this.getCluster(jobRequest);
        // Resolve the command for the job request based on command tags and cluster chosen
        final Command command = this.getCommand(jobRequest, cluster);
        // Resolve the applications to use based on the command that was selected
        final List<Application> applications = this.getApplications(jobRequest, command);
        // Now that we have command how much memory should the job use?
        final int memory = jobRequest.getMemory().orElse(command.getMemory().orElse(this.jobsProperties.getMemory().getDefaultJobMemory()));
        // Save all the runtime information
        this.setRuntimeEnvironment(jobId, cluster, command, applications, memory);
        final int maxJobMemory = this.jobsProperties.getMemory().getMaxJobMemory();
        if (memory > maxJobMemory) {
            jobStatus = JobStatus.INVALID;
            throw new GeniePreconditionException("Requested " + memory + " MB to run job which is more than the " + maxJobMemory + " MB allowed");
        }
        synchronized (this) {
            log.info("Checking if can run job {} on this node", jobRequest.getId());
            final int maxSystemMemory = this.jobsProperties.getMemory().getMaxSystemMemory();
            final int usedMemory = this.jobStateService.getUsedMemory();
            if (usedMemory + memory <= maxSystemMemory) {
                log.info("Job {} can run on this node as only {}/{} MB are used and requested {} MB", jobId, usedMemory, maxSystemMemory, memory);
                // Tell the system a new job has been scheduled so any actions can be taken
                log.info("Publishing job scheduled event for job {}", jobId);
                jobStateService.schedule(jobId, jobRequest, cluster, command, applications, memory);
                return jobId;
            } else {
                throw new GenieServerUnavailableException("Job " + jobId + " can't run on this node " + usedMemory + "/" + maxSystemMemory + " MB are used and requested " + memory + " MB");
            }
        }
    } catch (GenieConflictException e) {
        // Job has not been initiated so we don't have to call JobStateService.done()
        throw e;
    } catch (GenieException e) {
        //
        // Need to check if the job exists in the JobStateService
        // because this error can happen before the job is initiated.
        //
        if (jobStateService.jobExists(jobId)) {
            jobStateService.done(jobId);
            jobPersistenceService.updateJobStatus(jobId, jobStatus, e.getMessage());
        }
        throw e;
    } catch (Exception e) {
        //
        // Need to check if the job exists in the JobStateService
        // because this error can happen before the job is initiated.
        //
        if (jobStateService.jobExists(jobId)) {
            jobStateService.done(jobId);
            jobPersistenceService.updateJobStatus(jobId, jobStatus, e.getMessage());
        }
        throw new GenieServerException(e);
    } finally {
        this.coordinationTimer.record(System.nanoTime() - coordinationStart, TimeUnit.MILLISECONDS);
    }
}

[Buggy Hunk]
this.coordinationTimer.record(System.nanoTime() - coordinationStart, TimeUnit.MILLISECONDS);

[Patch]
this.coordinationTimer.record(System.nanoTime() - coordinationStart, TimeUnit.NANOSECONDS);

[Demonstration 2]

[Buggy Method]
@Override
public void run() {
    new HangmanFrame(new HangmanModel());
}

[Buggy Hunk]
new HangmanFrame(new HangmanModel());

[Patch]
HangmanFrame hangmanFrame = new HangmanFrame(new HangmanModel());

[Demonstration 3]

[Buggy Method]
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
    if (newState == BottomSheetBehavior.STATE_EXPANDED) {
        bottomSheet.requestLayout();
        bottomSheet.invalidate();
        imageGridView.smoothScrollToPosition(0);
        imageGridView.requestLayout();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

[Buggy Hunk]
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

[Patch]
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);