gnodet commented on code in PR #1944:
URL: https://github.com/apache/maven-mvnd/pull/1944#discussion_r4792846703


##########
common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalInputHandler.java:
##########
@@ -149,6 +150,10 @@ private void handleProjectInput(String projectId, int 
bytesToRead) throws IOExce
 
         while ((bytesToRead < 0 || idx < bytesToRead) && idx < buf.length) {
             int c = terminal.reader().read(timeout);
+            if (c == TerminalOutput.KEY_CTRL_C) {

Review Comment:
   **Same race condition issue**
   
   Similar to the comment in `handleControlKeys()`, there's a potential race on 
`daemonDispatch` here. The null check is at line 144, but the field is accessed 
at line 154 inside the loop.
   
   **Suggestion:** Store the volatile field in a local variable after the null 
check:
   ```java
   private void handleProjectInput(String projectId, int bytesToRead) throws 
IOException {
       Consumer<Message> receive = daemonReceive;
       if (receive == null) {
           return;
       }
       // ... use 'receive' instead of 'daemonReceive' throughout the method
       
       while ((bytesToRead < 0 || idx < bytesToRead) && idx < buf.length) {
           int c = terminal.reader().read(timeout);
           if (c == TerminalOutput.KEY_CTRL_C) {
               Consumer<Message> dispatch = daemonDispatch;
               if (dispatch != null) {
                   dispatch.accept(Message.BareMessage.CANCEL_BUILD_SINGLETON);
               }
               return;
           }
           // ... rest of loop using 'receive'
       }
   }
   ```
   
   _Claude Code on behalf of Guillaume Nodet_



##########
common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java:
##########
@@ -88,6 +88,10 @@ public class TerminalOutput implements ClientOutput {
      * the terminal the log for a given module once it's finished.
      */
     public static final int KEY_CTRL_M = 'M' & 0x1f;
+    /**
+     * The Ctrl+C key cancels the build.
+     */
+    public static final int KEY_CTRL_C = 'C' & 0x1f;
 

Review Comment:
   **Missing Javadoc**
   
   For consistency with the other `KEY_*` constants (lines 67-93), this should 
have a Javadoc comment explaining its purpose:
   
   ```java
   /**
    * The Ctrl+C key cancels the build.
    */
   public static final int KEY_CTRL_C = 'C' & 0x1f;
   ```
   
   _Claude Code on behalf of Guillaume Nodet_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to