diff --git a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/PropertiesMarshaller.java b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/PropertiesMarshaller.java index 936591b548..84a8d838c9 100644 --- a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/PropertiesMarshaller.java +++ b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/PropertiesMarshaller.java @@ -28,6 +28,7 @@ import java.util.Set; * Marshaller to write {@link CandidateComponentsMetadata} as properties. * * @author Stephane Nicoll + * @author Vedran Pavic * @since 5.0 */ abstract class PropertiesMarshaller { @@ -35,7 +36,7 @@ abstract class PropertiesMarshaller { public static void write(CandidateComponentsMetadata metadata, OutputStream out) throws IOException { Properties props = new SortedProperties(true); metadata.getItems().forEach(m -> props.put(m.getType(), String.join(",", m.getStereotypes()))); - props.store(out, ""); + props.store(out, null); } public static CandidateComponentsMetadata read(InputStream in) throws IOException { diff --git a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/SortedProperties.java b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/SortedProperties.java index 412e2bfb6b..e805f46e85 100644 --- a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/SortedProperties.java +++ b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/SortedProperties.java @@ -93,7 +93,7 @@ class SortedProperties extends Properties { super.store(baos, (this.omitComments ? null : comments)); String contents = new String(baos.toByteArray(), StandardCharsets.ISO_8859_1); for (String line : contents.split(EOL)) { - if (!this.omitComments || !line.startsWith("#")) { + if (!(this.omitComments && line.startsWith("#"))) { out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1)); } } @@ -105,7 +105,7 @@ class SortedProperties extends Properties { super.store(stringWriter, (this.omitComments ? null : comments)); String contents = stringWriter.toString(); for (String line : contents.split(EOL)) { - if (!this.omitComments || !line.startsWith("#")) { + if (!(this.omitComments && line.startsWith("#"))) { writer.write(line + EOL); } } diff --git a/spring-context-indexer/src/test/java/org/springframework/context/index/processor/PropertiesMarshallerTests.java b/spring-context-indexer/src/test/java/org/springframework/context/index/processor/PropertiesMarshallerTests.java index 7a7a8211ff..53c51a71ce 100644 --- a/spring-context-indexer/src/test/java/org/springframework/context/index/processor/PropertiesMarshallerTests.java +++ b/spring-context-indexer/src/test/java/org/springframework/context/index/processor/PropertiesMarshallerTests.java @@ -27,7 +27,6 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for {@link PropertiesMarshaller}. *