Repository: javaparser/javaparser

Issue #2647: Lexical Preservaton -- Injected code uses host's EOL not the source's
Created: 2020-05-04T21:13:24Z
Looks like @jlerbsc 's PR in #2646 fixes the issue described (thank you!), but it brings to the fore some other JavaParser behaviours that I am not sure are correct.
It seems that generated code is injected using the host's line endings. This is normally fine, but if the input text has a different line encoding then this leads to a source with mixed line endings. See the quoted post below, and the linked PR, for details.
#2646 (comment)

Digging deeper, @jlerbsc 's fix as given seems to work fine for fixing the problem presented in #2620 , but the tests fail due to the injected line endings not matching the parsed text.
For example if the parsed text has \r\n line endings, then on Ubuntu the hosts line endings (\n`) are injected -- ONLY on the injected lines.
I am unsure if this is a separate bug / issue that should be handled separately, or if it should be handled as part of this.
Ubuntu test failures
https://github.com/javaparser/javaparser/pull/2646/checks?check_run_id=644201141#step:6:1505
(line breaks / spacing added for clarity)
 [ERROR] Failures: 
[ERROR]   Issue2620Test.testWithCr:49->doTest:110 
expected: <    public class Foo { //comment\r    private String newField;\r    \r    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>
 but was: <    public class Foo { //comment\r    private String newField;\n    \n    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>

[ERROR]   Issue2620Test.testWithCrLf:59->doTest:110
 expected: <    public class Foo { //comment\r\n    private String newField;\r\n    \r\n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>
 but was: <    public class Foo { //comment\r\n    private String newField;\n    \n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>

Mac test failures
https://github.com/javaparser/javaparser/pull/2646/checks?check_run_id=644201231#step:6:1499
(line breaks / spacing added for clarity)
[ERROR] Failures: 
[ERROR]   Issue2620Test.testWithCr:49->doTest:110 

expected: <    public class Foo { //comment\r    private String newField;\r    \r    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>
 but was: <    public class Foo { //comment\r    private String newField;\n    \n    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>

[ERROR]   Issue2620Test.testWithCrLf:59->doTest:110 
expected: <    public class Foo { //comment\r\n    private String newField;\r\n    \r\n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>
 but was: <    public class Foo { //comment\r\n    private String newField;\n    \n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>

Windows test failures
https://github.com/javaparser/javaparser/pull/2646/checks?check_run_id=644201340#step:6:1505
(line breaks / spacing added for clarity)
[ERROR] Failures: 
[ERROR]   Issue2620Test.testWithCr:49->doTest:110
expected: <    public class Foo { //comment\r    private String newField;\r    \r    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>
 but was: <    public class Foo { //comment\r    private String newField;\r\n    \r\n    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>

[ERROR]   Issue2620Test.testWithLf:54->doTest:110 
expected: <    public class Foo { //comment\n    private String newField;\n    \n    private String a;\n        private String b;\n        private String c;\n        private String d;\n    }>
 but was: <    public class Foo { //comment\n    private String newField;\r\n    \r\n    private String a;\n        private String b;\n        private String c;\n        private String d;\n    }>


Originally posted by @MysterAitch in #2620 (comment)

Duplicate issue #2661: Line endings of injected code not matching the EOL in the parsed code
Created: 2020-05-10T17:42:42Z
Digging deeper, @jlerbsc 's fix as given seems to work fine for fixing the problem presented in #2620 , but the tests fail due to the injected line endings not matching the parsed text.
For example if the parsed text has \r\n line endings, then on Ubuntu the hosts line endings (\n`) are injected -- ONLY on the injected lines.
I am unsure if this is a separate bug / issue that should be handled separately, or if it should be handled as part of this.
Ubuntu test failures
https://github.com/javaparser/javaparser/pull/2646/checks?check_run_id=644201141#step:6:1505
(line breaks / spacing added for clarity)
 [ERROR] Failures: 
[ERROR]   Issue2620Test.testWithCr:49->doTest:110 
expected: <    public class Foo { //comment\r    private String newField;\r    \r    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>
 but was: <    public class Foo { //comment\r    private String newField;\n    \n    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>

[ERROR]   Issue2620Test.testWithCrLf:59->doTest:110
 expected: <    public class Foo { //comment\r\n    private String newField;\r\n    \r\n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>
 but was: <    public class Foo { //comment\r\n    private String newField;\n    \n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>


Mac test failures
https://github.com/javaparser/javaparser/pull/2646/checks?check_run_id=644201231#step:6:1499
(line breaks / spacing added for clarity)
[ERROR] Failures: 
[ERROR]   Issue2620Test.testWithCr:49->doTest:110 

expected: <    public class Foo { //comment\r    private String newField;\r    \r    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>
 but was: <    public class Foo { //comment\r    private String newField;\n    \n    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>

[ERROR]   Issue2620Test.testWithCrLf:59->doTest:110 
expected: <    public class Foo { //comment\r\n    private String newField;\r\n    \r\n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>
 but was: <    public class Foo { //comment\r\n    private String newField;\n    \n    private String a;\r\n        private String b;\r\n        private String c;\r\n        private String d;\r\n    }>



Windows test failures
https://github.com/javaparser/javaparser/pull/2646/checks?check_run_id=644201340#step:6:1505
(line breaks / spacing added for clarity)
[ERROR] Failures: 
[ERROR]   Issue2620Test.testWithCr:49->doTest:110
expected: <    public class Foo { //comment\r    private String newField;\r    \r    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>
 but was: <    public class Foo { //comment\r    private String newField;\r\n    \r\n    private String a;\r        private String b;\r        private String c;\r        private String d;\r    }>

[ERROR]   Issue2620Test.testWithLf:54->doTest:110 
expected: <    public class Foo { //comment\n    private String newField;\n    \n    private String a;\n        private String b;\n        private String c;\n        private String d;\n    }>
 but was: <    public class Foo { //comment\n    private String newField;\r\n    \r\n    private String a;\n        private String b;\n        private String c;\n        private String d;\n    }>


Originally posted by @MysterAitch in #2646 (comment)

Closing comment (2020-05-18T19:25:58Z): Duplicate of #2647 oops!