[Demonstration 1]

[Buggy Method]
public static <K, V> Map<K, V> factory(Function<K, V> function) {
    Objects.requireNonNull(function);
    return new Map<K, V>() {

        final Function<K, V> f = lazy(function);

        Map<K, V> defined = new HashMap<>();

        boolean cleared;

        @Override
        public int size() {
            return cleared ? defined.size() : Integer.MAX_VALUE;
        }

        @Override
        public boolean isEmpty() {
            return cleared && defined.isEmpty();
        }

        @Override
        public boolean containsKey(Object key) {
            return !cleared || defined.containsKey(key);
        }

        @Override
        public boolean containsValue(Object value) {
            throw new UnsupportedOperationException();
        }

        @SuppressWarnings("unchecked")
        @Override
        public V get(Object key) {
            return cleared ? defined.get(key) : f.apply((K) key);
        }

        @Override
        public V put(K key, V value) {
            return fluent(defined.put(key, value)).d0(__ -> f.apply(key)).origin();
        }

        @SuppressWarnings("unchecked")
        @Override
        public V remove(Object key) {
            return defined.replace((K) key, null);
        }

        @Override
        public void putAll(Map<? extends K, ? extends V> map) {
            defined.putAll(map);
        }

        @Override
        public void clear() {
            cleared = true;
            defined.clear();
        }

        @Override
        public Set<K> keySet() {
            return all();
        }

        @Override
        public Collection<V> values() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<java.util.Map.Entry<K, V>> entrySet() {
            throw new UnsupportedOperationException();
        }

        @Override
        public String toString() {
            return !cleared ? "{...}" : defined.toString();
        }
    };
}

[Buggy Hunk]
return all();

[Patch]
return !cleared ? all() : defined.keySet();

[Demonstration 2]

[Buggy Method]
private PropertiesBuilder buildProperties(final Path propertiesPath, final String prefix) throws ProcessBuilderException {
    try (final InputStream in = Files.newInputStream(propertiesPath)) {
        final Properties p = new Properties();
        p.load(in);
        Iterator<Entry<Object, Object>> iterator = p.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<Object, Object> entry = iterator.next();
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();
            getResult().add(prefix);
            getPrettyResult().append(prefix);
            getResult().add(key + "=" + value + " ");
            getPrettyResult().append(key).append("=").append(value).append(" ");
        }
        return this;
    } catch (IOException ioe) {
        String errMsg = "Error while processing properties file " + propertiesPath.normalize().toString();
        LOGGER.error(errMsg, ioe);
        throw new ProcessBuilderException(errMsg, ioe);
    }
}

[Buggy Hunk]
getResult().add(key + "=" + value + " ");

[Patch]
getResult().add(key + "=" + value);

[Demonstration 3]

[Buggy Method]
@Override
public Expression visitProduct(final List<Expression> operands) {
    //Calculates the product of all the constant terms in the node
    long constantTerm = 1;
    final List<Expression> factors = new ArrayList<>();
    for (final Expression o : operands) {
        if (o instanceof Constant) {
            final Constant c = (Constant) o;
            constantTerm *= c.getValue();
        } else {
            factors.add(o);
        }
    }
    if (constantTerm != 1) {
        //NOPMD
        factors.add(Constant.valueOf(constantTerm));
    }
    return ExpressionFactory.implode(NAryOperator.PRODUCT, factors);
}

[Buggy Hunk]
if (constantTerm != 1) { //NOPMD

[Patch]
if (constantTerm != 1 || factors.isEmpty()) { //NOPMD