Fix illegal argument exception when a proxied Sponge calculator adds an empty context (#780)

This commit is contained in:
Luck 2018-02-22 22:24:21 +00:00
parent 31d435dc2b
commit b1fa4263ed
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 25 additions and 38 deletions

View File

@ -32,6 +32,25 @@ import java.util.Set;
abstract class AbstractDelegatingContextSet extends AbstractSet<Context> implements DelegatingContextSet { abstract class AbstractDelegatingContextSet extends AbstractSet<Context> implements DelegatingContextSet {
@Override
public int size() {
return getDelegate().size();
}
@Override
public boolean isEmpty() {
return getDelegate().isEmpty();
}
@Override
public boolean contains(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
return !context.getKey().isEmpty() && !context.getValue().isEmpty() && getDelegate().has(context);
}
return false;
}
@Override @Override
public int hashCode() { public int hashCode() {
return getDelegate().hashCode(); return getDelegate().hashCode();

View File

@ -50,25 +50,6 @@ public class DelegatingImmutableContextSet extends AbstractDelegatingContextSet
return this.delegate; return this.delegate;
} }
@Override
public int size() {
return this.delegate.size();
}
@Override
public boolean isEmpty() {
return this.delegate.isEmpty();
}
@Override
public boolean contains(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
return this.delegate.has(context);
}
return false;
}
@Nonnull @Nonnull
@Override @Override
public Iterator<Context> iterator() { public Iterator<Context> iterator() {

View File

@ -50,25 +50,6 @@ public class DelegatingMutableContextSet extends AbstractDelegatingContextSet {
return this.delegate; return this.delegate;
} }
@Override
public int size() {
return this.delegate.size();
}
@Override
public boolean isEmpty() {
return this.delegate.isEmpty();
}
@Override
public boolean contains(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
return this.delegate.has(context);
}
return false;
}
@Nonnull @Nonnull
@Override @Override
public Iterator<Context> iterator() { public Iterator<Context> iterator() {
@ -80,6 +61,9 @@ public class DelegatingMutableContextSet extends AbstractDelegatingContextSet {
if (context == null) { if (context == null) {
throw new NullPointerException("context"); throw new NullPointerException("context");
} }
if (context.getKey().isEmpty() || context.getValue().isEmpty()) {
return false;
}
boolean has = this.delegate.has(context); boolean has = this.delegate.has(context);
this.delegate.add(context); this.delegate.add(context);
@ -90,6 +74,9 @@ public class DelegatingMutableContextSet extends AbstractDelegatingContextSet {
public boolean remove(Object o) { public boolean remove(Object o) {
if (o instanceof Context) { if (o instanceof Context) {
Context context = (Context) o; Context context = (Context) o;
if (context.getKey().isEmpty() || context.getValue().isEmpty()) {
return false;
}
boolean had = this.delegate.has(context); boolean had = this.delegate.has(context);
this.delegate.remove(context.getKey(), context.getValue()); this.delegate.remove(context.getKey(), context.getValue());
return had; return had;