Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Allow 0 ResourceTableChunks and TypeSpecChunk to be null #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions java/com/google/devrel/gmscore/tools/apk/arsc/PackageChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,15 @@ public Collection<TypeSpecChunk> getTypeSpecChunks() {
return typeSpecs.values();
}

/** For a given (1-based) type id, returns the {@link TypeSpecChunk} matching it. */
/**
* For a given (1-based) type id, returns the {@link TypeSpecChunk} matching it.
*/
public TypeSpecChunk getTypeSpecChunk(int id) {
return Preconditions.checkNotNull(typeSpecs.get(id));
if (typeSpecs.containsKey(id)) {
return typeSpecs.get(id);
} else {
return null;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ private void computeTypeSpecSizes(PackageChunk packageChunk,
// The 1 here is to convert back to a 1-based index.
TypeSpecChunk typeSpec = packageChunk.getTypeSpecChunk(i + 1);
// TypeSpecChunk entries share everything equally.
addSizes(usages[i], typeSpec.getOriginalChunkSize(), 0, 1);
if (typeSpec != null) {
addSizes(usages[i], typeSpec.getOriginalChunkSize(), 0, 1);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ResourceTableChunk extends ChunkWithChunks {
protected ResourceTableChunk(ByteBuffer buffer, @Nullable Chunk parent) {
super(buffer, parent);
// packageCount. We ignore this, because we already know how many chunks we have.
Preconditions.checkState(buffer.getInt() >= 1, "ResourceTableChunk package count was < 1.");
Preconditions.checkState(buffer.getInt() >= 0, "ResourceTableChunk package count was < 0.");
}

@Override
Expand Down