HubSpot / prettier-maven-plugin

Apache License 2.0
116 stars 23 forks source link

Plugin hangs forever (0.18, javaPrettierVersion 0.8.3 and above) #79

Open Lolmewn opened 1 year ago

Lolmewn commented 1 year ago

Hi!

I'm running into an issue where I'm upgrading to a new Java version (from 11 to 17), in which text blocks get introduced in my codebase. Without additional configuration, the maven plugin appears to use java-prettier 0.7.0, which does not support this newer java version yet. This was added in java-prettier 1.0.0. When setting the prettierJavaVersion configuration setting for the maven plugin, it seems any version above 0.8.2 hangs forever. A snippet from the maven debug output:

❯ mvn prettier:check -X                                                                                                                                                                                                                                                                                              ─╯
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /usr/local/Cellar/maven/3.8.7/libexec
Java version: 15.0.2, vendor: Amazon.com Inc., runtime: /Users/gjaltems/Library/Java/JavaVirtualMachines/corretto-15.0.2/Contents/Home
Default locale: en_NL, platform encoding: US-ASCII
OS name: "mac os x", version: "13.1", arch: "x86_64", family: "mac"
...
[DEBUG] Goal:          com.hubspot.maven.plugins:prettier-maven-plugin:0.18:check (default-cli)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <diffGeneratorType default-value="com.hubspot.maven.plugins.prettier.diff.DefaultDiffGenerator">${prettier.diffGenerator}</diffGeneratorType>
  <endOfLine>auto</endOfLine>
  <extractPrettierToTargetDirectory default-value="false"/>
  <fail default-value="true"/>
  <generateDiff default-value="false"/>
  <ignoreConfigFile default-value="false">true</ignoreConfigFile>
  <ignoreEditorConfig default-value="false">true</ignoreEditorConfig>
  <inputGlobs>${prettier.inputGlobs}</inputGlobs>
  <localRepository default-value="${settings.localRepository}"/>
  <nodePath default-value="">${prettier.nodePath}</nodePath>
  <nodeVersion default-value="16.13.2">${prettier.nodeVersion}</nodeVersion>
  <npmPath default-value="">${prettier.npmPath}</npmPath>
  <prettierJavaVersion default-value="0.7.0">1.0.2</prettierJavaVersion>
  <printWidth>100</printWidth>
  <project default-value="${project}"/>
  <skip default-value="false">false</skip>
  <tabWidth>2</tabWidth>
  <useTabs>false</useTabs>
  <pluginDescriptor default-value="${plugin}"/>
</configuration>
[INFO] --- prettier-maven-plugin:0.18:check (default-cli) @ project-restapi ---
[DEBUG] Determined os: MAC_X64
[DEBUG] Reusing cached node at: /Users/gjaltems/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64
[DEBUG] Reusing cached prettier-java at: /Users/gjaltems/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.0.2
[DEBUG] Running prettier with args: /Users/gjaltems/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node /Users/gjaltems/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.0.2/node_modules/prettier/bin-prettier.js --plugin=/Users/gjaltems/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.0.2/node_modules/prettier-plugin-java --color --print-width 100 --tab-width 2 --use-tabs false --end-of-line auto --no-config --no-editorconfig --check src/main/java/**/*.java src/test/java/**/*.java

Running the last command manually works just fine - it spits out a bunch of files that need formatting. I have tried using Java 15 instead of 17 (which was used for the logs above, as well), I have tried using pretter-maven-plugin versions 0.13, 0.17 and 0.18, and every java-prettier version between 0.7.0 and 1.0.0. I have also tried cleaning the maven caches.

Am I doing something wrong, or have I found a bug? Any help would be greatly appreciated!

jhaber commented 1 year ago

Thanks for the detailed report, can you try taking a thread dump while the process is stuck? (this should just involve running jstack {pid of the maven process})

Lolmewn commented 1 year ago

Of course! Here it is:

❯ jstack -e 977                                                                                                                                                                                                                                                                                                      ─╯
2023-01-18 15:46:34
Full thread dump OpenJDK 64-Bit Server VM (17.0.6+10-LTS mixed mode, sharing):

Threads class SMR info:
_java_thread_list=0x0000600000d14bc0, length=13, elements={
0x00007fc3d500ce00, 0x00007fc3d503fa00, 0x00007fc3d5042200, 0x00007fc3d58bd200,
0x00007fc3d5041000, 0x00007fc3d6826400, 0x00007fc3d6813000, 0x00007fc3d5040a00,
0x00007fc3d8010200, 0x00007fc3d6813600, 0x00007fc3d6865e00, 0x00007fc3d89f6a00,
0x00007fc3d5b55a00
}

"main" #1 prio=5 os_prio=31 cpu=1199.87ms elapsed=98.15s allocated=103M defined_classes=3114 tid=0x00007fc3d500ce00 nid=0x1603 runnable  [0x0000700005e15000]
   java.lang.Thread.State: RUNNABLE
        at java.io.FileInputStream.readBytes(java.base@17.0.6/Native Method)
        at java.io.FileInputStream.read(java.base@17.0.6/FileInputStream.java:276)
        at java.io.BufferedInputStream.read1(java.base@17.0.6/BufferedInputStream.java:282)
        at java.io.BufferedInputStream.read(java.base@17.0.6/BufferedInputStream.java:343)
        - locked <0x000000070cb76d88> (a java.lang.ProcessImpl$ProcessPipeInputStream)
        at sun.nio.cs.StreamDecoder.readBytes(java.base@17.0.6/StreamDecoder.java:270)
        at sun.nio.cs.StreamDecoder.implRead(java.base@17.0.6/StreamDecoder.java:313)
        at sun.nio.cs.StreamDecoder.read(java.base@17.0.6/StreamDecoder.java:188)
        - locked <0x000000070cb81df8> (a java.io.InputStreamReader)
        at java.io.InputStreamReader.read(java.base@17.0.6/InputStreamReader.java:177)
        at java.io.BufferedReader.fill(java.base@17.0.6/BufferedReader.java:162)
        at java.io.BufferedReader.readLine(java.base@17.0.6/BufferedReader.java:329)
        - locked <0x000000070cb81df8> (a java.io.InputStreamReader)
        at java.io.BufferedReader.readLine(java.base@17.0.6/BufferedReader.java:396)
        at com.hubspot.maven.plugins.prettier.AbstractPrettierMojo.execute(AbstractPrettierMojo.java:66)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:298)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@17.0.6/Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@17.0.6/NativeMethodAccessorImpl.java:77)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@17.0.6/DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(java.base@17.0.6/Method.java:568)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

"Reference Handler" #2 daemon prio=10 os_prio=31 cpu=0.30ms elapsed=98.14s allocated=0B defined_classes=0 tid=0x00007fc3d503fa00 nid=0x4a03 waiting on condition  [0x000070000652b000]
   java.lang.Thread.State: RUNNABLE
        at java.lang.ref.Reference.waitForReferencePendingList(java.base@17.0.6/Native Method)
        at java.lang.ref.Reference.processPendingReferences(java.base@17.0.6/Reference.java:253)
        at java.lang.ref.Reference$ReferenceHandler.run(java.base@17.0.6/Reference.java:215)

"Finalizer" #3 daemon prio=8 os_prio=31 cpu=0.18ms elapsed=98.14s allocated=32B defined_classes=0 tid=0x00007fc3d5042200 nid=0x4703 in Object.wait()  [0x000070000662e000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(java.base@17.0.6/Native Method)
        - waiting on <0x000000070d624398> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(java.base@17.0.6/ReferenceQueue.java:155)
        - locked <0x000000070d624398> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(java.base@17.0.6/ReferenceQueue.java:176)
        at java.lang.ref.Finalizer$FinalizerThread.run(java.base@17.0.6/Finalizer.java:172)

"Signal Dispatcher" #4 daemon prio=9 os_prio=31 cpu=0.24ms elapsed=98.13s allocated=480B defined_classes=0 tid=0x00007fc3d58bd200 nid=0x7803 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Service Thread" #5 daemon prio=9 os_prio=31 cpu=0.14ms elapsed=98.13s allocated=0B defined_classes=0 tid=0x00007fc3d5041000 nid=0x5903 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Monitor Deflation Thread" #6 daemon prio=9 os_prio=31 cpu=2.44ms elapsed=98.13s allocated=0B defined_classes=0 tid=0x00007fc3d6826400 nid=0x5a03 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #7 daemon prio=9 os_prio=31 cpu=1091.33ms elapsed=98.13s allocated=0B defined_classes=0 tid=0x00007fc3d6813000 nid=0x5b03 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task

"C1 CompilerThread0" #10 daemon prio=9 os_prio=31 cpu=629.88ms elapsed=98.13s allocated=7632B defined_classes=0 tid=0x00007fc3d5040a00 nid=0x7503 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task

"Sweeper thread" #11 daemon prio=9 os_prio=31 cpu=0.06ms elapsed=98.13s allocated=0B defined_classes=0 tid=0x00007fc3d8010200 nid=0x7403 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Notification Thread" #12 daemon prio=9 os_prio=31 cpu=0.06ms elapsed=98.12s allocated=0B defined_classes=0 tid=0x00007fc3d6813600 nid=0x7303 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Common-Cleaner" #13 daemon prio=8 os_prio=31 cpu=0.35ms elapsed=98.12s allocated=0B defined_classes=0 tid=0x00007fc3d6865e00 nid=0x7103 in Object.wait()  [0x000070000704f000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(java.base@17.0.6/Native Method)
        - waiting on <0x000000070d65a6c8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(java.base@17.0.6/ReferenceQueue.java:155)
        - locked <0x000000070d65a6c8> (a java.lang.ref.ReferenceQueue$Lock)
        at jdk.internal.ref.CleanerImpl.run(java.base@17.0.6/CleanerImpl.java:140)
        at java.lang.Thread.run(java.base@17.0.6/Thread.java:833)
        at jdk.internal.misc.InnocuousThread.run(java.base@17.0.6/InnocuousThread.java:162)

"process reaper" #16 daemon prio=10 os_prio=31 cpu=0.21ms elapsed=96.62s allocated=0B defined_classes=0 tid=0x00007fc3d89f6a00 nid=0x6b03 runnable  [0x000070000778b000]
   java.lang.Thread.State: RUNNABLE
        at java.lang.ProcessHandleImpl.waitForProcessExit0(java.base@17.0.6/Native Method)
        at java.lang.ProcessHandleImpl$1.run(java.base@17.0.6/ProcessHandleImpl.java:147)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@17.0.6/ThreadPoolExecutor.java:1136)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@17.0.6/ThreadPoolExecutor.java:635)
        at java.lang.Thread.run(java.base@17.0.6/Thread.java:833)

"Attach Listener" #17 daemon prio=9 os_prio=31 cpu=0.99ms elapsed=76.58s allocated=0B defined_classes=0 tid=0x00007fc3d5b55a00 nid=0x7b07 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"VM Thread" os_prio=31 cpu=5.82ms elapsed=98.14s tid=0x00007fc3d6109920 nid=0x4c03 runnable  

"GC Thread#0" os_prio=31 cpu=4.95ms elapsed=98.15s tid=0x00007fc3d4f07e90 nid=0x3603 runnable  

"GC Thread#1" os_prio=31 cpu=4.83ms elapsed=97.61s tid=0x00007fc3d4f18e70 nid=0x6203 runnable  

"GC Thread#2" os_prio=31 cpu=4.79ms elapsed=97.61s tid=0x00007fc3d4f194c0 nid=0x6403 runnable  

"GC Thread#3" os_prio=31 cpu=4.76ms elapsed=97.61s tid=0x00007fc3d620f0f0 nid=0x6603 runnable  

"GC Thread#4" os_prio=31 cpu=4.38ms elapsed=97.61s tid=0x00007fc3d620f950 nid=0x7003 runnable  

"GC Thread#5" os_prio=31 cpu=4.69ms elapsed=97.61s tid=0x00007fc3d4f19930 nid=0x6f03 runnable  

"GC Thread#6" os_prio=31 cpu=0.21ms elapsed=97.11s tid=0x00007fc3d6317490 nid=0x6903 runnable  

"GC Thread#7" os_prio=31 cpu=0.17ms elapsed=97.11s tid=0x00007fc3d6317900 nid=0x6d03 runnable  

"G1 Main Marker" os_prio=31 cpu=0.05ms elapsed=98.15s tid=0x00007fc3d6204630 nid=0x2f03 runnable  

"G1 Conc#0" os_prio=31 cpu=0.03ms elapsed=98.15s tid=0x00007fc3d4f08300 nid=0x3103 runnable  

"G1 Refine#0" os_prio=31 cpu=0.05ms elapsed=98.15s tid=0x00007fc3d6106bf0 nid=0x5403 runnable  

"G1 Service" os_prio=31 cpu=15.62ms elapsed=98.15s tid=0x00007fc3d6204eb0 nid=0x4103 runnable  

"VM Periodic Task Thread" os_prio=31 cpu=52.16ms elapsed=98.12s tid=0x00007fc3d620ad60 nid=0x7203 waiting on condition  

JNI global refs: 9, weak refs: 0
Lolmewn commented 1 year ago

Update: It seems the node process keeps running. After killing it via the Activity Monitor, the plugin spits out the classes with code-formatting issues. Is this then a problem with the maven plugin or with prettier-java itself?

jhaber commented 1 year ago

Hmm, but node doesn't keep running when you run it directly on the commandline with the same args?

Lolmewn commented 1 year ago

When I run node with the same commandline args as the one in the debug logs, node exits on its own correctly (after some 19s). So no, weirdly enough this only appears to happen through the plugin.

Tingil79 commented 4 months ago

Having the same issue with Java 21, prettier-maven-plugin 0.22 and prettier-java 2.6.0.

glucazeau commented 3 months ago

We have the same issue (Windows only) with Java 17, prettier-maven and prettierJavaVersion 1.5.0.

Upgrading the plugin or the prettierJavaVersion does not change anything but testing with a snapshot from the linked pull-request makes the issue go away.

Any chance to merge it soon?