Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running with --replace does not converge #562

Open
kmurphy4 opened this issue Feb 5, 2021 · 0 comments
Open

Running with --replace does not converge #562

kmurphy4 opened this issue Feb 5, 2021 · 0 comments

Comments

@kmurphy4
Copy link

kmurphy4 commented Feb 5, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant