This is an automated email from the ASF dual-hosted git repository.

sdanilov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new b67688b751 IGNITE-19220 Prohibit marking NetworkMessage with 
Marshallable (#1901)
b67688b751 is described below

commit b67688b75163051ffc7c5d204c93f290623795e0
Author: Semyon Danilov <[email protected]>
AuthorDate: Thu Apr 6 14:53:10 2023 +0400

    IGNITE-19220 Prohibit marking NetworkMessage with Marshallable (#1901)
---
 .../processor/messages/MessageImplGenerator.java   | 12 ++++++++-
 .../processor/TransferableObjectProcessorTest.java | 11 ++++++++
 ...MessageWithMarshallableNetworkMessageField.java | 29 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git 
a/modules/network-annotation-processor/src/main/java/org/apache/ignite/internal/network/processor/messages/MessageImplGenerator.java
 
b/modules/network-annotation-processor/src/main/java/org/apache/ignite/internal/network/processor/messages/MessageImplGenerator.java
index 84e63cc954..071bd0f463 100644
--- 
a/modules/network-annotation-processor/src/main/java/org/apache/ignite/internal/network/processor/messages/MessageImplGenerator.java
+++ 
b/modules/network-annotation-processor/src/main/java/org/apache/ignite/internal/network/processor/messages/MessageImplGenerator.java
@@ -48,6 +48,7 @@ import javax.lang.model.type.TypeMirror;
 import javax.tools.Diagnostic;
 import org.apache.ignite.internal.network.processor.MessageClass;
 import org.apache.ignite.internal.network.processor.MessageGroupWrapper;
+import org.apache.ignite.internal.network.processor.ProcessingException;
 import org.apache.ignite.internal.network.processor.TypeUtils;
 import org.apache.ignite.internal.tostring.IgniteToStringInclude;
 import org.apache.ignite.internal.tostring.S;
@@ -102,7 +103,8 @@ public class MessageImplGenerator {
 
         // create a field and a getter implementation for every getter in the 
message interface
         for (ExecutableElement getter : getters) {
-            var getterReturnType = TypeName.get(getter.getReturnType());
+            TypeMirror getterType = getter.getReturnType();
+            TypeName getterReturnType = TypeName.get(getterType);
 
             String getterName = getter.getSimpleName().toString();
 
@@ -111,6 +113,14 @@ public class MessageImplGenerator {
                     .addModifiers(Modifier.PRIVATE);
 
             boolean isMarshallable = getter.getAnnotation(Marshallable.class) 
!= null;
+            boolean isNetworkMessage = typeUtils.isSubType(getterType, 
NetworkMessage.class);
+
+            if (isMarshallable && isNetworkMessage) {
+                String error =
+                        "Failed to process " + message.className() + ": " + 
getterName + " is both NetworkMessage and @Marshallable";
+
+                throw new ProcessingException(error);
+            }
 
             if (!isMarshallable) {
                 fieldBuilder.addModifiers(Modifier.FINAL);
diff --git 
a/modules/network/src/test/java/org/apache/ignite/internal/network/processor/TransferableObjectProcessorTest.java
 
b/modules/network/src/test/java/org/apache/ignite/internal/network/processor/TransferableObjectProcessorTest.java
index ec119c6ab5..bb7c0346ba 100644
--- 
a/modules/network/src/test/java/org/apache/ignite/internal/network/processor/TransferableObjectProcessorTest.java
+++ 
b/modules/network/src/test/java/org/apache/ignite/internal/network/processor/TransferableObjectProcessorTest.java
@@ -249,6 +249,17 @@ public class TransferableObjectProcessorTest {
         );
     }
 
+    /**
+     * Tests that compilation fails if message's field is both {@link 
NetworkMessage} and marked
+     * as {@link org.apache.ignite.network.annotations.Marshallable}.
+     */
+    @Test
+    void testFieldBothNetworkMessageAndMarkedMarshallable() {
+        Compilation compilation = 
compile("MessageWithMarshallableNetworkMessageField");
+
+        assertThat(compilation).hadErrorContaining("msgField is both 
NetworkMessage and @Marshallable");
+    }
+
     /**
      * Compiles the given network message.
      */
diff --git 
a/modules/network/src/test/resources/org/apache/ignite/internal/network/processor/MessageWithMarshallableNetworkMessageField.java
 
b/modules/network/src/test/resources/org/apache/ignite/internal/network/processor/MessageWithMarshallableNetworkMessageField.java
new file mode 100644
index 0000000000..07f49676b0
--- /dev/null
+++ 
b/modules/network/src/test/resources/org/apache/ignite/internal/network/processor/MessageWithMarshallableNetworkMessageField.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.network.processor;
+
+import org.apache.ignite.internal.network.message.ScaleCubeMessage;
+import org.apache.ignite.network.NetworkMessage;
+import org.apache.ignite.network.annotations.Marshallable;
+import org.apache.ignite.network.annotations.Transferable;
+
+@Transferable(1)
+public interface MessageWithMarshallableNetworkMessageField extends 
NetworkMessage {
+    @Marshallable
+    ScaleCubeMessage msgField();
+}

Reply via email to