Skip to content

Commit ee4b460

Browse files
committed
Fix erasing of LVT entries with the same index.
1 parent fe5eb48 commit ee4b460

1 file changed

Lines changed: 26 additions & 32 deletions

File tree

src/main/java/de/oceanlabs/mcp/mcinjector/adaptors/ApplyMap.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import java.util.Collections;
66
import java.util.Comparator;
77
import java.util.HashMap;
8+
import java.util.HashSet;
89
import java.util.List;
910
import java.util.Map;
11+
import java.util.Set;
1012
import java.util.logging.Level;
1113
import java.util.logging.Logger;
1214

@@ -133,7 +135,6 @@ private MethodNode processLVT(String clsName, String classSig, MethodNode mn)
133135
throw new RuntimeException("Incorrect argument count: " + types.size() + " -> " + params.size());
134136
}
135137

136-
137138
// Add labels to the start and end if they are not already labels
138139
AbstractInsnNode tmp = mn.instructions.getFirst();
139140
if (tmp == null)
@@ -147,52 +148,45 @@ else if (tmp.getType() != AbstractInsnNode.LABEL)
147148
else if (tmp.getType() != AbstractInsnNode.LABEL)
148149
mn.instructions.insert(tmp, new LabelNode());
149150

151+
Map<Integer, String> parNames = new HashMap<Integer, String>();
152+
for (int x = 0, y = 0; x < params.size(); x++, y++)
153+
{
154+
String arg = params.get(x);
155+
String desc = types.get(x).getDescriptor();
156+
parNames.put(y, arg);
157+
if (desc.equals("J") || desc.equals("D")) y++;
158+
}
159+
150160
//Grab the start and end labels
151161
LabelNode start = (LabelNode)mn.instructions.getFirst();
152162
LabelNode end = (LabelNode)mn.instructions.getLast();
163+
Set<Integer> found = new HashSet<Integer>();
164+
165+
if (mn.localVariables == null)
166+
mn.localVariables = new ArrayList<LocalVariableNode>();
153167

154-
Map<Integer, LocalVariableNode> lvt = new HashMap<Integer, LocalVariableNode>();
155-
if (mn.localVariables != null)
168+
for (LocalVariableNode lvn : mn.localVariables)
156169
{
157-
for (LocalVariableNode lvn : mn.localVariables)
170+
String name = parNames.get(lvn.index);
171+
if (name != null)
158172
{
159-
if (lvt.containsKey(lvn.index))
160-
{
161-
log.info(" DUPLICATE LVT INDEX: " + lvn.index);
162-
}
163-
lvt.put(lvn.index, lvn);
173+
log.fine(" ReNaming argument (" + lvn.index + "): " + lvn.name + " -> " + name);
174+
lvn.name = name;
175+
found.add(lvn.index);
164176
}
165177
}
166-
167-
for (int x = 0, y = x; x < params.size(); x++, y++)
178+
for (int x = 0, y = 0; x < params.size(); x++, y++)
168179
{
169180
String arg = params.get(x);
170181
String desc = types.get(x).getDescriptor();
171-
LocalVariableNode lvn = lvt.get(y);
172-
173-
if (arg.equals(""))
174-
{
175-
log.fine(" Skipping argument " + x + " (" + y + ") -> " + desc);
176-
}
177-
else
178-
{
179-
if (lvn != null)
180-
{
181-
log.fine(" ReNaming argument " + x + " (" + y + "): " + lvn.name + " -> " + arg);
182-
lvn.name = arg;
183-
}
184-
else
185-
{
186-
log.fine(" Naming argument " + x + " (" + y + ") -> " + arg + " " + desc);
187-
lvt.put(y, new LocalVariableNode(arg, desc, null, start, end, y));
188-
}
189-
}
182+
if (found.contains(y))
183+
continue;
190184

185+
log.fine(" Naming argument " + x + " (" + y + ") -> " + arg + " " + desc);
186+
mn.localVariables.add(new LocalVariableNode(arg, desc, null, start, end, y));
191187
if (desc.equals("J") || desc.equals("D")) y++;
192188
}
193189

194-
mn.localVariables = new ArrayList<LocalVariableNode>();
195-
mn.localVariables.addAll(lvt.values());
196190
Collections.sort(mn.localVariables, new Comparator<LocalVariableNode>()
197191
{
198192
@Override

0 commit comments

Comments
 (0)