IGNITE-28972 Generation must fail Message to byte[] marshalling - #13461
IGNITE-28972 Generation must fail Message to byte[] marshalling#13461nizhikov wants to merge 13 commits into
Conversation
anton-vinogradov
left a comment
There was a problem hiding this comment.
Thanks for picking this up, the gap is real.
One blocker: the check is applied before MarshalledKind is computed, so it keys off the field type while the rule actually depends on the companion wire field. ELEMENTS (an X[] companion) and MAP are written by the communication protocol, not by a marshaller, so Message elements there are correct and must stay allowed. As written, Set<SomeMessage> with a SomeMessage[] companion is rejected even though generation emits writeObjectArray(..., MessageCollectionItemType.MSG) and produces no marshaller blob at all. The current tests do not catch it: testMarshalledCollectionMessage uses GridCacheVersion, which is not a Message, and the symmetric map case is allowed only because map form is excluded by hand.
Computing the kind first and checking only BLOB and ELEMENT_BLOBS fixes the false positive, lets the same walk cover nested generics, and keeps all 49 MessageProcessorTest tests green including the four new ones (verified locally, the error text can stay as is).
The rest are smaller notes inline.
| if (ann == null) | ||
| return null; | ||
|
|
||
| ensureCorrectlyAnnotated(field, ann); |
There was a problem hiding this comment.
The check runs before the kind is computed, so it judges the field type instead of the companion and rejects a working pattern (Set + GridTopicMessage[] companion) that the protocol writes itself. Please move the check after the kind is known and apply it only to BLOB and ELEMENT_BLOBS.
| public class MarshalledOnMessageCollection implements Message { | ||
| /** */ | ||
| @Marshalled("msgBytes") | ||
| Collection<TestMessage> msgColl; |
There was a problem hiding this comment.
Do we need to check also List and List in the same way?
There was a problem hiding this comment.
Generator works for all Collections, don't think we want to check all of the Collection implementations in tests.
| /** */ | ||
| public class MarshalledOnMessageMap implements Message { | ||
| /** */ | ||
| @Marshalled("bytes") |
There was a problem hiding this comment.
Do we need to check also @Marshalled with keys() and values()?
There was a problem hiding this comment.
Checked in TestMarshalledMapMessage
There was a problem hiding this comment.
There are Collection<GridCacheVersion> and Collection<GridCacheVersion> mapVals; Expected: byte[] arrays
| /** */ | ||
| public class MarshalledOnMessageMap implements Message { | ||
| /** */ | ||
| @Marshalled("bytes") |
There was a problem hiding this comment.
There are Collection<GridCacheVersion> and Collection<GridCacheVersion> mapVals; Expected: byte[] arrays
|
|
||
| /** Test that {@code @Marshalled} annotation on raw {@link Map} fail generation. */ | ||
| @Test | ||
| public void testRawMapFailGeneration() { |
There was a problem hiding this comment.
Join with testRawCollectionFailGeneration? + The same, do we need "TestMessage.java"
| return MarshalledKind.MAP; | ||
| res = MarshalledKind.MAP; | ||
| else { | ||
| TypeMirror wire = requireEnclosed(enclosed, ann.value(), "@Marshalled").asType(); |
There was a problem hiding this comment.
Just a notise. Annotation here look as something important. Important to search. But is onle for the error.
| import org.apache.ignite.plugin.extensions.communication.Message; | ||
|
|
||
| /** */ | ||
| public class MarshalledOnMessageArray implements Message { |
There was a problem hiding this comment.
Let's call such messages as IncorrectXXX
| public class MarshalledOnMessageCollection2 implements Message { | ||
| /** */ | ||
| @Marshalled("msgBytes") | ||
| Collection<TestMessage> msgColl; |
There was a problem hiding this comment.
Should we check wildcards as well, like Collection<? extends TestMessage>?
| if (foundMessageToBytesTransformation(field.asType(), field, ann)) { | ||
| env.getMessager().printMessage(Diagnostic.Kind.ERROR, | ||
| "Message must be written by dedicated message serializers. " + | ||
| "Remove @" + Marshalled.class.getSimpleName() + " annotation and remove companion field.", field); |
Possible compatibility issues. Please, check rolling upgrade casesThis PR modifies protected classes (with Order annotation). Affected files:
|
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
The Contribution Checklist
The description explains WHAT and WHY was made instead of HOW.
The following pattern must be used:
IGNITE-XXXX Change summarywhereXXXX- number of JIRA issue.(see the Maintainers list)
the
green visaattached to the JIRA ticket (see tabPR Checkat TC.Bot - Instance 1 or TC.Bot - Instance 2)Notes
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com #ignite channel.