Fix some null issues in the immutable implementation

This commit is contained in:
Ben Gruver 2012-11-01 22:41:06 -07:00
parent db49fd7714
commit dccca459e9
2 changed files with 11 additions and 2 deletions

View File

@ -70,7 +70,11 @@ public class ImmutableMethodImplementation implements MethodImplementation {
this.debugItems = Objects.firstNonNull(debugItems, ImmutableList.<ImmutableDebugItem>of()); this.debugItems = Objects.firstNonNull(debugItems, ImmutableList.<ImmutableDebugItem>of());
} }
public static ImmutableMethodImplementation of(MethodImplementation methodImplementation) { @Nullable
public static ImmutableMethodImplementation of(@Nullable MethodImplementation methodImplementation) {
if (methodImplementation == null) {
return null;
}
if (methodImplementation instanceof ImmutableMethodImplementation) { if (methodImplementation instanceof ImmutableMethodImplementation) {
return (ImmutableMethodImplementation)methodImplementation; return (ImmutableMethodImplementation)methodImplementation;
} }

View File

@ -38,6 +38,7 @@ import org.jf.dexlib2.iface.value.*;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class ImmutableEncodedValue implements EncodedValue { public class ImmutableEncodedValue implements EncodedValue {
@ -47,7 +48,11 @@ public class ImmutableEncodedValue implements EncodedValue {
this.type = type; this.type = type;
} }
public static ImmutableEncodedValue of(EncodedValue encodedValue) { @Nullable
public static ImmutableEncodedValue of(@Nullable EncodedValue encodedValue) {
if (encodedValue == null) {
return null;
}
switch (encodedValue.getValueType()) { switch (encodedValue.getValueType()) {
case ValueType.BYTE: case ValueType.BYTE:
return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue); return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue);