From a2bf7f64bc39c6631ddaff28d87c1a982ba5dfa6 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Thu, 17 Oct 2013 16:46:06 -0700 Subject: [PATCH] Fix issue with BuilderPackedSwitchPayload instructions The transformation is performed lazily, and the keys were incorrect when iterating over the elements more than once --- .../instruction/BuilderPackedSwitchPayload.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/instruction/BuilderPackedSwitchPayload.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/instruction/BuilderPackedSwitchPayload.java index de89ecf4..de74e4a0 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/instruction/BuilderPackedSwitchPayload.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/instruction/BuilderPackedSwitchPayload.java @@ -31,7 +31,6 @@ package org.jf.dexlib2.builder.instruction; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.jf.dexlib2.Format; @@ -55,13 +54,11 @@ public class BuilderPackedSwitchPayload extends BuilderSwitchPayload implements if (switchElements == null) { this.switchElements = ImmutableList.of(); } else { - this.switchElements = Lists.transform(switchElements, new Function() { - int key = startKey; - @Nullable @Override public BuilderSwitchElement apply(@Nullable Label target) { - assert target != null; - return new BuilderSwitchElement(BuilderPackedSwitchPayload.this, key++, target); - } - }); + this.switchElements = Lists.newArrayList(); + int key = startKey; + for (Label target: switchElements) { + this.switchElements.add(new BuilderSwitchElement(this, key++, target)); + } } }