Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMQ-9530]Fix SelectorAwareVirtualTopicInterceptor ClassCastException if next is not Topic. #1247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Nikita-Shupletsov
Copy link

@Nikita-Shupletsov Nikita-Shupletsov commented Jul 9, 2024

next is not guaranteed to be Topic. If there is plugin that injects another DestinationInterceptor, the code will fail with ClassCastException.

Added a method to correctly unwrap next.

Ran:

  • AMQ4899Test.java
  • VirtualTopicSelectorTest.java
  • JavaVirtualDestTest.java
  • SelectorAwareVTThatDropsMessagesWhenNoConsumer.java
  • TwoBrokerVirtualTopicSelectorAwareForwardingTest.java
  • VirtualConsumerDemandTest.java
    to make sure there is no regression

@mattrpav
Copy link
Contributor

What is the use case for this?

@Nikita-Shupletsov
Copy link
Author

What is the use case for this?

you mean the use case of having a DestinationFilter after SelectorAwareVirtualTopicInterceptor?

I my case I add an interceptor to all topics. and that interceptor coexists with the rest of interceptors. and some topics can be vistual topics. it's technically possible on the plugin side to check if there is a virtual topic interceptor and not add my interceptor. But I checked other interceptors(this one for example) and they handle this situation correctly, so I thought it would be a positive change in general. In case people decide to do something similar in the future, they will not need to work around the edge case.

@mattrpav
Copy link
Contributor

A couple of points:

  1. This change needs to be a JIRA
  2. This needs a unit test with an example configured w/ another DestinationFilter on top of Virtual Topic
  3. If we are going to fix it, we should adapt all the Virtual Destinations to use the same set of methods.

@Nikita-Shupletsov Nikita-Shupletsov changed the title Fix SelectorAwareVirtualTopicInterceptor ClassCastException if next is not Topic. [AMQ-9530]Fix SelectorAwareVirtualTopicInterceptor ClassCastException if next is not Topic. Jul 10, 2024
@Nikita-Shupletsov
Copy link
Author

1. This change needs to be a JIRA

Done. https://issues.apache.org/jira/browse/AMQ-9530

2. This needs a unit test with an example configured w/ another DestinationFilter on top of Virtual Topic

Updated VirtualTopicSelectorTest, as it's basically tests SelectorAwareVirtualTopicInterceptor. Also used it to initially reproduce the issue(see the ticket).

3. If we are going to fix it, we should adapt all the Virtual Destinations to use the same set of methods.

There are no issues like this in other pars of the Virtual Destination code. only in SelectorAwareVirtualTopicInterceptor

@mattrpav
Copy link
Contributor

There are no issues like this in other pars of the Virtual Destination code. only in SelectorAwareVirtualTopicInterceptor

MappedQueueFilter has a nearly identical method:

ref:

private BaseDestination getBaseDestination(Destination virtualDest) {

@mattrpav mattrpav self-requested a review July 16, 2024 17:56
@Nikita-Shupletsov
Copy link
Author

There are no issues like this in other pars of the Virtual Destination code. only in SelectorAwareVirtualTopicInterceptor

MappedQueueFilter has a nearly identical method:

ref:

private BaseDestination getBaseDestination(Destination virtualDest) {

are you proposing to extract this method to a helper class? If I create a new class, let's say VirtualTopicSupport or VistualTopicHelper, will it be okay? or do you have a particular place in mind fir it?

@mattrpav
Copy link
Contributor

mattrpav commented Aug 6, 2024

Yes, a base class that contains the lookup method to unwrap the destination to get to the root (real) destination that can be used by VirtualTopic and MappedQueueFilter.

ie BaseVirtualDestination(Inteceptor|Filter)

@Nikita-Shupletsov
Copy link
Author

Yes, a base class that contains the lookup method to unwrap the destination to get to the root (real) destination that can be used by VirtualTopic and MappedQueueFilter.

ie BaseVirtualDestination(Inteceptor|Filter)

sounds good! done

@jbonofre jbonofre self-requested a review September 11, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants