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

View File

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