[Demonstration 1]

[Buggy Method]
private CompilationUnit validateFile(String fileName) {
    if (this.isOurFile(fileName) == false) {
        return null;
    }
    String relName = fileName.substring(this.compRootFolder.length());
    String prefix;
    ComponentType ct;
    if (relName.isEmpty()) {
        /*
			 * files in root have to be application
			 */
        ct = null;
        prefix = "";
    } else {
        ct = ComponentType.getTypeByFolder(relName);
        if (ct == null) {
            logger.info("file " + fileName + " is inside comp folder, but sub-folder is not for any simplity resource. File not validated");
            return null;
        }
        prefix = ct.getFolderPrefix();
    }
    /*
		 * file name is rootName + prefix + resource-name. We have t get
		 * resource name from this as fileIs. for example fileName =
		 * "comp/service/tp/mod/s.xml" then fileId would be "mod/s.xml"
		 */
    String folderPrefix = this.compRootFolder + prefix;
    String fileId = fileName.substring(folderPrefix.length());
    CompilationUnit cpu = new CompilationUnit(fileId, ct, true);
    CompilationUnit oldCpu = this.compilationUnits.put(fileId, cpu);
    Map<String, Comp> map = ct == null ? this.apps : this.comps[ct.getIdx()];
    this.removeComps(map, oldCpu);
    if (ct == null) {
        this.validateApp(fileName, cpu);
    } else if (ct.isGrouped()) {
        this.validateGroup(ct, fileName, cpu);
    } else {
        this.validateSingle(ct, fileName, cpu);
    }
    return cpu;
}

[Buggy Hunk]
Map<String, Comp> map = ct == null ? this.apps : this.comps[ct.getIdx()];

[Patch]
Map map = ct == null ? this.apps : this.comps[ct.getIdx()];

[Demonstration 2]

[Buggy Method]
public Object eval(Story story) throws InkRunTimeException {
    Stack<Object> stack = new Stack<>();
    for (String token : getRPN(story)) {
        if (operators.containsKey(token)) {
            Object v1 = stack.pop();
            Object v2 = stack.pop();
            stack.push(operators.get(token).eval(v2, v1));
        } else if (story.hasVariable(token)) {
            try {
                Object obj = story.getValue(token);
                if (obj instanceof Boolean) {
                    if (((Boolean) obj).booleanValue())
                        stack.push(BigDecimal.ONE);
                    else
                        stack.push(BigDecimal.ZERO);
                } else if (obj instanceof String) {
                    stack.push(obj);
                } else {
                    stack.push(((BigDecimal) obj).round(mc));
                }
            } catch (InkRunTimeException e) {
                e.printStackTrace();
            }
        } else if (story.hasFunction(token)) {
            Function f = story.functions.get(token);
            List<Object> p = new ArrayList<>(!f.numParamsVaries() ? f.getNumParams() : 0);
            // pop parameters off the stack until we hit the start of
            // this function's parameter list
            while (!stack.isEmpty() && stack.peek() != PARAMS_START) {
                p.add(0, (BigDecimal) stack.pop());
            }
            if (stack.peek() == PARAMS_START) {
                stack.pop();
            }
            if (!f.numParamsVaries() && p.size() != f.getNumParams()) {
                throw new ExpressionException("Function " + token + " expected " + f.getNumParams() + " parameters, got " + p.size());
            }
            Object fResult = f.eval(p, story);
            stack.push(fResult);
        } else if (story.checkObject(token)) {
            String var = token.substring(0, token.indexOf("."));
            String function = token.substring(token.indexOf(".") + 1);
            Object val = story.getValue(var);
            List<Object> p = new ArrayList<>();
            // pop parameters off the stack until we hit the start of  this function's parameter list
            while (!stack.isEmpty() && stack.peek() != PARAMS_START) {
                p.add(0, (BigDecimal) stack.pop());
            }
            if (stack.peek() == PARAMS_START) {
                stack.pop();
            }
            Class[] paramTypes = new Class[p.size()];
            Object[] params = new Object[p.size()];
            for (int i = 0; i < p.size(); i++) {
                paramTypes[i] = p.get(i).getClass();
                params[i] = p.get(i);
            }
            Class valClass = val.getClass();
            try {
                Method m = valClass.getMethod(function, paramTypes);
                Object fResult = m.invoke(val, params);
                stack.push(fResult);
            } catch (NoSuchMethodException e) {
                throw new InkRunTimeException("Could not identify a method " + function + " on variable " + var + " with those parameters");
            } catch (InvocationTargetException e) {
                throw new InkRunTimeException("Could not invoke a method " + function + " on variable " + var + " with those parameters");
            } catch (IllegalAccessException e) {
                throw new InkRunTimeException("Could not access a method " + function + " on variable " + var + " with those parameters");
            }
        } else if ("(".equals(token)) {
            stack.push(PARAMS_START);
        } else {
            if (isNumber(token))
                stack.push(new BigDecimal(token, mc));
            else
                stack.push(token);
        }
    }
    Object obj = stack.pop();
    if (obj instanceof BigDecimal)
        return ((BigDecimal) obj).stripTrailingZeros();
    return obj;
}

[Buggy Hunk]
p.add(0, (BigDecimal) stack.pop());

[Patch]
p.add(0, stack.pop());

[Demonstration 3]

[Buggy Method]
@Test
public void testFileUpload() throws Exception {
    String userID = RandomStringUtils.random(15);
    String path = "/";
    String fileName = "my_file.js";
    UUID fileContent = UUID.randomUUID();
    MockMultipartFile file = new MockMultipartFile("file", fileName, null, RandomStringUtils.random(400).getBytes());
    Descriptor baseDescriptor = Descriptor.builder().children(new ArrayList<>()).type(Descriptor.DescriptorType.DIR).build();
    Descriptor fileDescriptor = Descriptor.builder().name(fileName).type(Descriptor.DescriptorType.FILE).fileContent(fileContent).build();
    User user = User.builder().baseDescriptor(baseDescriptor).build();
    when(userDAO.findOne(Criteria.where("_id").is(userID))).thenReturn(user);
    when(descriptorManagementService.findDescriptorByPath(baseDescriptor, path, true)).thenReturn(baseDescriptor);
    when(descriptorManagementService.createNewFileDescriptor(eq(baseDescriptor), eq(file.getOriginalFilename()), any(InputStream.class))).thenReturn(fileDescriptor);
    assertFalse("That's why in previous mock we have any", file.getInputStream().equals(file.getInputStream()));
    RequestBuilder request = MockMvcRequestBuilders.fileUpload("/fs/file").file(file).sessionAttr("userID", userID).param("path", path);
    mockMvc.perform(request).andExpect(status().is2xxSuccessful()).andExpect(jsonPath("$.children").doesNotExist()).andExpect(jsonPath("$.type").value(Descriptor.DescriptorType.FILE.toString())).andExpect(jsonPath("$.path").value(PathUtils.join(path, fileName))).andExpect(jsonPath("$.name").value(fileName));
    verify(userDAO).findOne(Criteria.where("_id").is(userID));
    verify(descriptorManagementService).findDescriptorByPath(baseDescriptor, path, true);
    verify(descriptorManagementService).createNewFileDescriptor(eq(baseDescriptor), eq(file.getOriginalFilename()), any(InputStream.class));
}

[Buggy Hunk]
String fileName = "my_file.js";

[Patch]
String fileName = RandomStringUtils.random(15);