Check for null before using Iterables.filter

This commit is contained in:
Ben Gruver 2013-10-10 19:46:02 -07:00
parent 216ca5376b
commit 6926ece0cd
2 changed files with 19 additions and 18 deletions

View File

@ -31,10 +31,7 @@
package org.jf.dexlib2.immutable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.*;
import org.jf.dexlib2.base.reference.BaseTypeReference;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.ClassDef;
@ -71,6 +68,13 @@ public class ImmutableClassDef extends BaseTypeReference implements ClassDef {
@Nullable Collection<? extends Annotation> annotations,
@Nullable Iterable<? extends Field> fields,
@Nullable Iterable<? extends Method> methods) {
if (fields == null) {
fields = ImmutableList.of();
}
if (methods == null) {
methods = ImmutableList.of();
}
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;

View File

@ -67,27 +67,24 @@ public class BuilderClassDef extends BaseTypeReference implements ClassDef {
@Nonnull BuilderAnnotationSet annotations,
@Nullable Iterable<? extends BuilderField> fields,
@Nullable Iterable<? extends BuilderMethod> methods) {
if (fields == null) {
fields = ImmutableList.of();
}
if (methods == null) {
methods = ImmutableList.of();
}
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = interfaces;
this.sourceFile = sourceFile;
this.annotations = annotations;
if (fields == null) {
this.staticFields = ImmutableSortedSet.of();
this.instanceFields = ImmutableSortedSet.of();
} else {
this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
}
if (methods == null) {
this.directMethods = ImmutableSortedSet.of();
this.virtualMethods = ImmutableSortedSet.of();
} else {
this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
}
@Nonnull @Override public String getType() { return type.getType(); }
@Override public int getAccessFlags() { return accessFlags; }