google / google-java-format

Reformats Java source code to comply with Google Java Style.
Other
5.65k stars 857 forks source link

Format failed with instructions to raise a bug... #1173

Closed big-andy-coates closed 1 month ago

big-andy-coates commented 1 month ago

Raising as requested :)

msg.txt

FYI, changing:

"""
UPDATE %s SET varchar_col = 'bar', timestamp_col = '2009-01-03T02:54:25.001';
INSERT INTO %s (varchar_col, timestamp_col) VALUES ( 'car','2017-08-24T01:57:37.000')"""

To:

"""
UPDATE %s SET varchar_col = 'bar', timestamp_col = '2009-01-03T02:54:25.001';
INSERT INTO %s (varchar_col, timestamp_col) VALUES ( 'car','2017-08-24T01:57:37.000')
"""

Resolved the issue...

Gradle config:

plugins {
    id 'com.diffplug.spotless' version "6.22.0"
    ...
}

  spotless {
      java {
          googleJavaFormat("1.15.0").aosp().reflowLongStrings()
          indentWithSpaces()
          importOrder()
          removeUnusedImports()
          trimTrailingWhitespace()
          endWithNewline()
          toggleOffOn("formatting:off", "formatting:on")
          targetExclude("**/build/generated/source*/**/*.*")
      }
  }
tbroyer commented 1 month ago

Fwiw, the message also says:

google-java-format 1.15.0 is currently being used, but outdated.
google-java-format 1.17.0 is the recommended version, which may have fixed this problem.
google-java-format 1.17.0 requires JVM 11+.

and the latest GJF version is 1.24.0 (and text block support has been improved a couple times in the last few versions)

So maybe just use the latest version?

cushon commented 1 month ago

Thanks for passing the crash report along. Can you try using the latest version as tbroyer suggested? If you're still seeing a crash, please re-open and include the original input that the formatter is crashing on.