Repository: decorators-squad/eo-yaml (java)
Issue: Ghost Comments
Version: 6.0.1
Issue: Is a scalar node has both a comment and an inline comment, the next node will appear to have that same comment, even though it has no comments at all. For example if node B has an inline comment and the comment "hello world" above it and node C has no comments, then node C will also have the comment "hello world" even though it is not supposed to!

Given the following YML file

```
a: a
#hello world
b: b #inline
c: c
```

Read Using

```
YamlMapping mapping = ...
YamlNode Bnode = mapping.value("b");
System.out.println("B Node:" + Bnode.comment().value());
YamlNode Cnode = mapping.value("c");
System.out.println("C Node: " + Cnode.comment().value());
```

Will output 

```
B Node:hello world
inline
C Node: hello world
```

This output is obviously incorrect because the C node does not have any comments. The correct output should be as follows. 

```
B Node: hello world
inline
C Node: 
```

Pull request description: #497 fixed gost comment in scalars
Fixes #497 

Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/FirstCommentFound.java b/src/main/java/com/amihaiemil/eoyaml/FirstCommentFound.java
index a2ec204..af61547 100644
--- a/src/main/java/com/amihaiemil/eoyaml/FirstCommentFound.java
+++ b/src/main/java/com/amihaiemil/eoyaml/FirstCommentFound.java
@@ -114,10 +114,8 @@ final class FirstCommentFound implements YamlLines {
             final YamlLine line = iterator.next();
             boolean hasComment = !line.comment().isEmpty();
             boolean notYamlStart = !"---".equals(line.trimmed());
-            if(notYamlStart && hasComment) {
-                if(line.trimmed().startsWith("#")) {
-                    comment.add(line);
-                }
+            if(notYamlStart && hasComment && line.trimmed().startsWith("#")) {
+                comment.add(line);
             } else {
                 break;
             }


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
index b9d63dc..e489fe8 100644
--- a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
@@ -1182,6 +1182,23 @@ public final class RtYamlInputTest {
             Matchers.nullValue());
     }
 
+    /**
+     * Unit test for issue 497 (ghost scalar comment).
+     * @throws IOException If something goes wrong.
+     */
+    @Test
+    public void shouldReadScalarCommentsProperly() throws IOException {
+        final String filename = "issue_497_ghost_comment.yml";
+
+        final YamlMapping read = new RtYamlInput(
+            new FileInputStream("src/test/resources/" + filename)
+        ).readYamlMapping();
+        MatcherAssert.assertThat(
+            read.toString(),
+            Matchers.equalTo(this.readTestResource(filename))
+        );
+    }
+
     /**
      * Read a test resource file's contents.
      * @param fileName File to read.
diff --git a/src/test/resources/issue_497_ghost_comment.yml b/src/test/resources/issue_497_ghost_comment.yml
new file mode 100644
index 0000000..ee128ae
--- /dev/null
+++ b/src/test/resources/issue_497_ghost_comment.yml
@@ -0,0 +1,4 @@
+key_a: a
+# hello world
+key_b: b # inline
+key_c: c # ccc inline
\ No newline at end of file