remove if's for stream filter
Every Optional.isPresent() can be replaced with the fluent Optional.ifPresent() which takes a Consumer function arg (that can be lambda expr) which accepts the value of the Optional.get()

properties.entrySet().stream().filter(property -&gt; existProp.containsKey(property.getKey()))
.findFirst().ifPresent(foundPropertyValue -&gt; {
  // Same key already exists 
  LOG.warn("Property with key {} already exists in requires {}", foundPropertyValue.getKey(), requires.get(reqidx).getName());
  // in case the existing property has the same value (check only for value of type String)
  if (foundPropertyValue.getValue() instanceof String
      &amp;&amp; existProp.get(foundPropertyValue.getKey()) instanceof String
      &amp;&amp; (foundPropertyValue.getValue()).equals(existProp.get(foundPropertyValue.getKey()))) {
        throw new Exception("Property " + foundPropertyValue.getKey() + "  exists already with value " + foundPropertyValue.getValue() + " in requires " + requiresName);
  }
});