ARTEMIS-2766 Improving AMQPMessageSymbolSearch for correctness

This commit is contained in:
Clebert Suconic 2020-05-16 01:33:32 -04:00
parent 55582772f9
commit 1420ad7745
2 changed files with 17 additions and 10 deletions

Binary file not shown.

View File

@ -37,15 +37,22 @@ import org.apache.qpid.proton.codec.TypeConstructor;
final class AMQPMessageSymbolSearch { final class AMQPMessageSymbolSearch {
// used to quick search for MessageAnnotations // used to quick search for MessageAnnotations
private static final IdentityHashMap<Class<?>, Boolean> MSG_BODY_TYPES; private static final IdentityHashMap<Class<?>, Boolean> MSG_ANNOTATIONS_STOPSET;
private static final IdentityHashMap<Class<?>, Boolean> APPLICATION_PROPERTIES_STOPSET;
static { static {
// we're including MessageAnnotations here because it will still cause termination // we're including MessageAnnotations here because it will still cause termination
final List<Class<?>> classList = Arrays.asList(MessageAnnotations.class, Properties.class, List<Class<?>> classList = Arrays.asList(MessageAnnotations.class, Properties.class,
ApplicationProperties.class, Data.class, ApplicationProperties.class, Data.class,
AmqpSequence.class, AmqpValue.class, Footer.class); AmqpSequence.class, AmqpValue.class, Footer.class);
MSG_BODY_TYPES = new IdentityHashMap<>(classList.size()); MSG_ANNOTATIONS_STOPSET = new IdentityHashMap<>(classList.size());
classList.forEach(clazz -> MSG_BODY_TYPES.put(clazz, Boolean.TRUE)); classList.forEach(clazz -> MSG_ANNOTATIONS_STOPSET.put(clazz, Boolean.TRUE));
// we're including ApplicationProperties here because it will still cause termination
classList = Arrays.asList(ApplicationProperties.class, Data.class,
AmqpSequence.class, AmqpValue.class, Footer.class);
APPLICATION_PROPERTIES_STOPSET = new IdentityHashMap<>(classList.size());
classList.forEach(clazz -> APPLICATION_PROPERTIES_STOPSET.put(clazz, Boolean.TRUE));
} }
public static KMPNeedle kmpNeedleOf(Symbol symbol) { public static KMPNeedle kmpNeedleOf(Symbol symbol) {
@ -58,14 +65,14 @@ final class AMQPMessageSymbolSearch {
public static boolean anyMessageAnnotations(final ReadableBuffer data, final KMPNeedle[] needles) { public static boolean anyMessageAnnotations(final ReadableBuffer data, final KMPNeedle[] needles) {
return lookupOnSection(MessageAnnotations.class, data, needles, 0); return lookupOnSection(MSG_ANNOTATIONS_STOPSET, MessageAnnotations.class, data, needles, 0);
} }
public static boolean anyApplicationProperties(final ReadableBuffer data, final KMPNeedle[] needles, int startAt) { public static boolean anyApplicationProperties(final ReadableBuffer data, final KMPNeedle[] needles, int startAt) {
return lookupOnSection(ApplicationProperties.class, data, needles, startAt); return lookupOnSection(APPLICATION_PROPERTIES_STOPSET, ApplicationProperties.class, data, needles, startAt);
} }
private static boolean lookupOnSection(final Class section, final ReadableBuffer data, final KMPNeedle[] needles, final int startAt) { private static boolean lookupOnSection(IdentityHashMap<Class<?>, Boolean> stopSet, final Class section, final ReadableBuffer data, final KMPNeedle[] needles, final int startAt) {
DecoderImpl decoder = TLSEncode.getDecoder(); DecoderImpl decoder = TLSEncode.getDecoder();
final int position = data.position(); final int position = data.position();
decoder.setBuffer(data.position(startAt)); decoder.setBuffer(data.position(startAt));
@ -73,7 +80,7 @@ final class AMQPMessageSymbolSearch {
while (data.hasRemaining()) { while (data.hasRemaining()) {
TypeConstructor<?> constructor = decoder.readConstructor(); TypeConstructor<?> constructor = decoder.readConstructor();
final Class<?> typeClass = constructor.getTypeClass(); final Class<?> typeClass = constructor.getTypeClass();
if (MSG_BODY_TYPES.containsKey(typeClass)) { if (MSG_ANNOTATIONS_STOPSET.containsKey(typeClass)) {
if (section.equals(typeClass)) { if (section.equals(typeClass)) {
final int start = data.position(); final int start = data.position();
constructor.skipValue(); constructor.skipValue();