google-java-format
google-java-format copied to clipboard
Inconsistent line-length formatting between files with CRLF and files with LF line endings
Setup
Version: google-java-format-1.7-all-deps.jar Machines:
- MacOS 10.14.5
- Fedora Linux 30
Problem
The formatter splits lines inconsistently when the file has CRLF line endings vs. LF line endings. Specifically, when a line is 100 characters long (the max for the formatter) and the file has CRLF line endings, the formatter will split the line prematurely.
This happens at the command line and when using the formatter in IntelliJ 2019.1.3.
Expected behavior
Line endings should not change the behavior of the formatter with respect to line length.
Steps to Reproduce
public class Something {
private static enum Response {
ONE;
}
// This is not a Rest API method(end point).
public Response aaaaaBbbbbbCccccccc(int aaaaaaCcccccccDd, String aaaaaaCcccccccEeee) {
try {
// ...other code was here...
// check if client universe name provided by UI is null
if (aaaaaaCcccccccEeee == null) {
return DdddEeeeConstants.SOMETHING_TYPE.equals(aaaaaaCccccccc.getAaaaaaCcccccccTttt())
? RestUtils.buildDDResponse(
DDExceptionUtils.getStatusMessageFromList(DDStatusCodeConstants.DD_CODE_25003)) /*
* Watchlist name is needed for processing this request.
*/
: RestUtils.buildDDResponse(
DDExceptionUtils.getStatusMessageFromList(DDStatusCodeConstants.DD_CODE_25002)); /*
* Portfolio name is needed for processing this request.
*/
}
// ...other code was here...
return ONE;
} catch (FFFGgggException e) {
return RestUtils.handleBusinessException(e);
} catch (Exception e) {
return RestUtils.handleSystemException(e);
}
}
}
- Copy the code above into a file named
with-lf.java
, and a file namedwith-crlf.java
- Ensure each file has the proper line endings
- Run
dos2unix
onwith-lf.java
(or use an editor in which you can control the line endings) - Run
unix2dos
onwith-crlf.java
(or use an editor in which you can control the line endings) - Run
java -jar /path/to/google-java-format-1.7-all-deps.jar -r /path/to/with-lf.java
- Run
java -jar /path/to/google-java-format-1.7-all-deps.jar -r /path/to/with-crlf.java
- Run
diff -uw /path/to/with-crlf.java /path/to/with-lf.java
to see the differences