PakhomovAlexander commented on code in PR #7914:
URL: https://github.com/apache/ignite-3/pull/7914#discussion_r3032513943


##########
modules/network-annotation-processor/src/main/java/org/apache/ignite/internal/network/processor/messages/MessageImplGenerator.java:
##########
@@ -653,20 +651,11 @@ private static void 
generateEqualsAndHashCode(TypeSpec.Builder messageImplBuilde
                 .addStatement("var otherMessage = ($T)other", 
message.implClassName())
                 .addStatement(comparisonStatement.build());
 
-        hashCode
-                .addStatement("int result = 0");
+        first = true;

Review Comment:
   If a message has **zero getters**, the `for` loop never executes, so 
`result` is never declared — but `hashCode.addStatement("return result")` is 
still emitted unconditionally on the next line. This would produce code that 
doesn't compile:
   
   ```java
   @Override
   public int hashCode() {
       return result; // result is not declared
   }
   ```
   
   The old code handled this by emitting `int result = 0` unconditionally 
*before* the loop. I'd suggest either:
   1. Adding `hashCode.addStatement("int result = 0")` before the loop (same as 
old code), or
   2. Guarding with `if (message.getters().isEmpty()) { 
hashCode.addStatement("return 0"); } else { ... }`
   
   This is probably unreachable today (all messages likely have at least one 
field), but it's a latent trap for anyone adding a marker/tag message with no 
fields in the future.



-- 
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