google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

Running with --replace does not converge

Open kmurphy4 opened this issue 4 years ago • 0 comments

I'm trying to integrate this tool into my codebase at work, and I came across a curious situation where google-java-format will always add an empty comment. This is probably better shown than explained, so here's a minimal reproduction:

$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)

$ java -jar /tmp/google-java-format-all-deps.jar -version
google-java-format: Version 1.9

$ cat /tmp/GoogleJavaFormatTest.java # the original
public class GoogleJavaFormatTest {
    //String testString = " thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}

$ java -jar /tmp/google-java-format-all-deps.jar --replace /tmp/GoogleJavaFormatTest.java
$ cat /tmp/GoogleJavaFormatTest.java 
public class GoogleJavaFormatTest {
  // String testString = "
  // thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}

$ java -jar /tmp/google-java-format-all-deps.jar --replace /tmp/GoogleJavaFormatTest.java
$ cat /tmp/GoogleJavaFormatTest.java 
public class GoogleJavaFormatTest {
  // String testString = "
  //
  // thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}

$ java -jar /tmp/google-java-format-all-deps.jar --replace /tmp/GoogleJavaFormatTest.java
$ cat /tmp/GoogleJavaFormatTest.java 
public class GoogleJavaFormatTest {
  // String testString = "
  //
  //
  // thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}

As you can see, each time I run with --replace is adds a new line just containing //\n. I have no idea why this particular string is breaking it -- I tried others and they didn't seem to break it.

Please let me know if there's any more information I can provide!

kmurphy4 avatar Feb 05 '21 19:02 kmurphy4