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

Fix NPE in DefaultMessageFactory if receiving unknown message type > 32 #789

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/org/jgroups/DefaultMessageFactory.java
Original file line number Diff line number Diff line change
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