Skip to content

IGNITE-28972 Generation must fail Message to byte[] marshalling - #13461

Open
nizhikov wants to merge 13 commits into
apache:masterfrom
nizhikov:IGNITE-28972
Open

IGNITE-28972 Generation must fail Message to byte[] marshalling#13461
nizhikov wants to merge 13 commits into
apache:masterfrom
nizhikov:IGNITE-28972

Conversation

@nizhikov

Copy link
Copy Markdown
Contributor

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

  • There is a single JIRA ticket related to the pull request.
  • The web-link to the pull request is attached to the JIRA ticket.
  • The JIRA ticket has the Patch Available state.
  • The pull request body describes changes that have been made.
    The description explains WHAT and WHY was made instead of HOW.
  • The pull request title is treated as the final commit message.
    The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • A reviewer has been mentioned through the JIRA comments
    (see the Maintainers list)
  • The pull request has been checked by the Teamcity Bot and
    the green visa attached to the JIRA ticket (see tab PR Check at 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.

@anton-vinogradov anton-vinogradov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread modules/core/src/test/resources/codegen/InternalMessage.java Outdated
Comment thread modules/core/src/test/resources/codegen/InternalMessageContainer.java Outdated
Comment thread modules/core/src/test/resources/codegen/MarshalledOnMessageArray2.java Outdated
public class MarshalledOnMessageCollection implements Message {
/** */
@Marshalled("msgBytes")
Collection<TestMessage> msgColl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check also List and List in the same way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check also @Marshalled with keys() and values()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked in TestMarshalledMapMessage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are Collection<GridCacheVersion> and Collection<GridCacheVersion> mapVals; Expected: byte[] arrays

Comment thread modules/core/src/test/resources/codegen/MarshalledOnMessageSet.java Outdated
/** */
public class MarshalledOnMessageMap implements Message {
/** */
@Marshalled("bytes")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call such messages as IncorrectXXX

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

public class MarshalledOnMessageCollection2 implements Message {
/** */
@Marshalled("msgBytes")
Collection<TestMessage> msgColl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And set an @order annotation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@github-actions

Copy link
Copy Markdown

Possible compatibility issues. Please, check rolling upgrade cases

This PR modifies protected classes (with Order annotation).
Changes to these classes can break rolling upgrade compatibility.

Affected files:

  • modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants