Always store node metadata keys in a HashMap, not IdentityHashMap, and ensure immutability when built

This commit is contained in:
Luck 2020-03-04 12:44:47 +00:00
parent 85451a9a20
commit bb3afa21a4
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 7 additions and 9 deletions

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.common.node;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.node.utils.ShorthandParser;
@ -74,7 +75,7 @@ public abstract class AbstractNode<N extends ScopedNode<N, B>, B extends NodeBui
this.value = value;
this.expireAt = expireAt;
this.contexts = contexts;
this.metadata = metadata;
this.metadata = ImmutableMap.copyOf(metadata);
this.resolvedShorthand = this instanceof PermissionNode ? ImmutableList.copyOf(ShorthandParser.expandShorthand(this.key)) : ImmutableList.of();

View File

@ -42,8 +42,8 @@ import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Objects;
@ -54,13 +54,6 @@ public abstract class AbstractNodeBuilder<N extends ScopedNode<N, B>, B extends
protected ImmutableContextSet.Builder context;
protected final Map<NodeMetadataKey<?>, Object> metadata;
protected AbstractNodeBuilder() {
this.value = true;
this.expireAt = 0L;
this.context = new ImmutableContextSetImpl.BuilderImpl();
this.metadata = new IdentityHashMap<>();
}
protected AbstractNodeBuilder(boolean value, long expireAt, ImmutableContextSet context, Map<NodeMetadataKey<?>, Object> metadata) {
this.value = value;
this.expireAt = expireAt;
@ -68,6 +61,10 @@ public abstract class AbstractNodeBuilder<N extends ScopedNode<N, B>, B extends
this.metadata = new HashMap<>(metadata);
}
protected AbstractNodeBuilder() {
this(true, 0L, ImmutableContextSet.empty(), Collections.emptyMap());
}
@Override
public @NonNull B value(boolean value) {
this.value = value;