Fix annotation/initial value issues when iterating over fields/methods in a DexBackedDexFile

Make sure to make a new annotation/initial value iterator when making a new
field/method iterator
This commit is contained in:
Ben Gruver 2013-10-12 02:14:02 -07:00
parent 9f48c72390
commit 902ba7d72d

View File

@ -152,16 +152,16 @@ public class DexBackedClassDef extends BaseTypeReference implements ClassDef {
final int staticInitialValuesOffset = final int staticInitialValuesOffset =
dexFile.readSmallUint(classDefOffset + ClassDefItem.STATIC_VALUES_OFFSET); dexFile.readSmallUint(classDefOffset + ClassDefItem.STATIC_VALUES_OFFSET);
final int fieldsStartOffset = reader.getOffset(); final int fieldsStartOffset = reader.getOffset();
final AnnotationsDirectory.AnnotationIterator annotationIterator =
annotationsDirectory.getFieldAnnotationIterator();
final StaticInitialValueIterator staticInitialValueIterator =
StaticInitialValueIterator.newOrEmpty(dexFile, staticInitialValuesOffset);
return new Iterable<DexBackedField>() { return new Iterable<DexBackedField>() {
@Nonnull @Nonnull
@Override @Override
public Iterator<DexBackedField> iterator() { public Iterator<DexBackedField> iterator() {
final AnnotationsDirectory.AnnotationIterator annotationIterator =
annotationsDirectory.getFieldAnnotationIterator();
final StaticInitialValueIterator staticInitialValueIterator =
StaticInitialValueIterator.newOrEmpty(dexFile, staticInitialValuesOffset);
return new VariableSizeLookaheadIterator<DexBackedField>(dexFile, fieldsStartOffset) { return new VariableSizeLookaheadIterator<DexBackedField>(dexFile, fieldsStartOffset) {
private int count; private int count;
@Nullable private FieldReference previousField; @Nullable private FieldReference previousField;
@ -212,14 +212,15 @@ public class DexBackedClassDef extends BaseTypeReference implements ClassDef {
DexReader reader = dexFile.readerAt(getInstanceFieldsOffset()); DexReader reader = dexFile.readerAt(getInstanceFieldsOffset());
final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory(); final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory();
final AnnotationsDirectory.AnnotationIterator annotationIterator =
annotationsDirectory.getFieldAnnotationIterator();
final int fieldsStartOffset = reader.getOffset(); final int fieldsStartOffset = reader.getOffset();
return new Iterable<DexBackedField>() { return new Iterable<DexBackedField>() {
@Nonnull @Nonnull
@Override @Override
public Iterator<DexBackedField> iterator() { public Iterator<DexBackedField> iterator() {
final AnnotationsDirectory.AnnotationIterator annotationIterator =
annotationsDirectory.getFieldAnnotationIterator();
return new VariableSizeLookaheadIterator<DexBackedField>(dexFile, fieldsStartOffset) { return new VariableSizeLookaheadIterator<DexBackedField>(dexFile, fieldsStartOffset) {
private int count; private int count;
@Nullable private FieldReference previousField; @Nullable private FieldReference previousField;
@ -278,16 +279,17 @@ public class DexBackedClassDef extends BaseTypeReference implements ClassDef {
DexReader reader = dexFile.readerAt(getDirectMethodsOffset()); DexReader reader = dexFile.readerAt(getDirectMethodsOffset());
final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory(); final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory();
final AnnotationsDirectory.AnnotationIterator methodAnnotationIterator =
annotationsDirectory.getMethodAnnotationIterator();
final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator =
annotationsDirectory.getParameterAnnotationIterator();
final int methodsStartOffset = reader.getOffset(); final int methodsStartOffset = reader.getOffset();
return new Iterable<DexBackedMethod>() { return new Iterable<DexBackedMethod>() {
@Nonnull @Nonnull
@Override @Override
public Iterator<DexBackedMethod> iterator() { public Iterator<DexBackedMethod> iterator() {
final AnnotationsDirectory.AnnotationIterator methodAnnotationIterator =
annotationsDirectory.getMethodAnnotationIterator();
final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator =
annotationsDirectory.getParameterAnnotationIterator();
return new VariableSizeLookaheadIterator<DexBackedMethod>(dexFile, methodsStartOffset) { return new VariableSizeLookaheadIterator<DexBackedMethod>(dexFile, methodsStartOffset) {
private int count; private int count;
@Nullable private MethodReference previousMethod; @Nullable private MethodReference previousMethod;
@ -334,13 +336,14 @@ public class DexBackedClassDef extends BaseTypeReference implements ClassDef {
DexReader reader = dexFile.readerAt(getVirtualMethodsOffset()); DexReader reader = dexFile.readerAt(getVirtualMethodsOffset());
final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory(); final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory();
final int methodsStartOffset = reader.getOffset();
return new Iterable<DexBackedMethod>() {
final AnnotationsDirectory.AnnotationIterator methodAnnotationIterator = final AnnotationsDirectory.AnnotationIterator methodAnnotationIterator =
annotationsDirectory.getMethodAnnotationIterator(); annotationsDirectory.getMethodAnnotationIterator();
final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator = final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator =
annotationsDirectory.getParameterAnnotationIterator(); annotationsDirectory.getParameterAnnotationIterator();
final int methodsStartOffset = reader.getOffset();
return new Iterable<DexBackedMethod>() {
@Nonnull @Nonnull
@Override @Override
public Iterator<DexBackedMethod> iterator() { public Iterator<DexBackedMethod> iterator() {