Issue
I am using mvn clean install command and seems like maven goes into some deadlock while compiling classes, it remains in this state -
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service-nextgen ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ service-nextgen ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 363 source files to C:\Users\service-nextgen\target\classes
If I visualize thread dump using java Visual VM, I get following information:
"RMI TCP Connection(3)-3.202.32.1" #20 daemon prio=5 os_prio=0 tid=0x000000001f246000 nid=0x2454 runnable [0x000000002118e000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
- locked <0x00000000ff832010> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$240(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/10873147.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- <0x00000000ff8321d0> (a java.util.concurrent.ThreadPoolExecutor$Worker)
"main" #1 prio=5 os_prio=0 tid=0x0000000001ff8000 nid=0x2b38 runnable [0x0000000002501000]
java.lang.Thread.State: RUNNABLE
at java.lang.Object.hashCode(Native Method)
at java.util.HashMap.hash(HashMap.java:338)
at java.util.HashMap.get(HashMap.java:556)
at com.sun.tools.javac.comp.Infer$InferenceContext.cachedCapture(Infer.java:2309)
not sure how to get the root cause.
Solution
I was able to identify the issue after adding Compiler args in maven compiler plugin: <compilerArgs> <arg>-verbose</arg> <arg>-Xlint:all,-options,-path</arg> </compilerArgs>
This displayed the classes one by one during compilation and I was able to see where compiler was getting stuck.
The maven configuration looks something like this:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
<arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
One possible class of culprits for errors of this kind are Annotations Processors which generate code during the compilation phase.
Answered By - Rhishi Nema
Answer Checked By - Marilyn (JavaFixing Volunteer)