Are there any impacts or repercussions if the dos2unix command is run on Java source files, right before they are compiled? The Java files would be downloaded from a CVS repository in Linux and then compiled to a jar by an Ant script. Thanks.
3 Answers
No need to even test this (theoretically): in the Java languages, line breaks bare no semantical meaning. Therefore there presence is irrelevant (to the compiler that is).
So a human reader mind find it very unpleasant to look at source code that has zero newlines, or a newline in just any place where they are legit - for the compiler, as said: it doesn't matter.
Therefore tools like dos2unix are not supposed to make any changes to source code that could make a "semantical" difference.
And of course: the real answer is: don't spend your time worrying about line breaks. Invest it into moving your the whole system from 1999 to 2018 (by getting replacing say CVS with git, and Ant with maven/gradle for example).

- 137,827
- 25
- 176
- 248
-
Well newlines certainly have _some_ meaning, since they count as token-separating whitespace. E.g., `a\nb` is two separate tokens, a and b while `ab` is one token, ab. That said, as it pertains to the question your point stands I think - that exception doesn't invalidate transforming newlines (but removing them may be dangerous). – BeeOnRope Mar 06 '18 at 23:20
Practical test
First I created a test file with Linux line endings called Main.java
, unsurprisingly on Linux this compiled.
0x63 [ c] 0x6c [ l] 0x61 [ a] 0x73 [ s] 0x73 [ s]
0x20 [ ] 0x4d [ M] 0x61 [ a] 0x69 [ i] 0x6e [ n]
0x20 [ ] 0x7b [ {] 0x0a [\n] 0x7d [ }] 0x0a [\n]
0x0a [\n]
Converting to DOS endings gave this:
0x63 [ c] 0x6c [ l] 0x61 [ a] 0x73 [ s] 0x73 [ s]
0x20 [ ] 0x4d [ M] 0x61 [ a] 0x69 [ i] 0x6e [ n]
0x20 [ ] 0x7b [ {] 0x0d [\r] 0x0a [\n] 0x7d [ }]
0x0d [\r] 0x0a [\n] 0x0d [\r] 0x0a [\n]
Which still compiles, and converting back gives:
0x63 [ c] 0x6c [ l] 0x61 [ a] 0x73 [ s] 0x73 [ s]
0x20 [ ] 0x4d [ M] 0x61 [ a] 0x69 [ i] 0x6e [ n]
0x20 [ ] 0x7b [ {] 0x0a [\n] 0x7d [ }] 0x0a [\n]
0x0a [\n]
Which is the same as before
Line endings
The difference between the Windows (dos) and Linux / Mac (unix) line endings is that the line ending on unix is \n
whereas the line ending on dos is \r\n
.
Results
- As the unix2dos / dos2unix only changes line endings it does not change the contents
- At least on Linux, javac can compile source files with either line ending successfully.

- 6,719
- 1
- 26
- 49