Skip to content

Commit

Permalink
Fix NPE in DefaultMessageFactory if receiving unknown message type > 32
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Apr 24, 2024
1 parent b59333e commit ceca494
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/org/jgroups/DefaultMessageFactory.java
Expand Up @@ -14,7 +14,7 @@
public class DefaultMessageFactory implements MessageFactory {
protected static final byte MIN_TYPE=32;
protected final Supplier<? extends Message>[] creators=new Supplier[MIN_TYPE];
protected Map<Short,Supplier<? extends Message>> map;
protected Map<Short,Supplier<? extends Message>> map=new HashMap<>();

public DefaultMessageFactory() {
creators[Message.BYTES_MSG]=BytesMessage::new;
Expand All @@ -38,8 +38,6 @@ public <T extends MessageFactory> T register(short type, Supplier<? extends Mess
Objects.requireNonNull(generator, "the creator must be non-null");
if(type < MIN_TYPE)
throw new IllegalArgumentException(String.format("type (%d) must be >= 32", type));
if(map == null)
map=new HashMap<>();
if(map.containsKey(type))
throw new IllegalArgumentException(String.format("type %d is already taken", type));
map.put(type, generator);
Expand Down

0 comments on commit ceca494

Please sign in to comment.