Skip to content

Commit

Permalink
Fix NPE in variable remapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Aug 23, 2024
1 parent a6f7865 commit c45692c
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.modules.decompiler.vars;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.ClassesProcessor.ClassNode;
import org.jetbrains.java.decompiler.main.DecompilerContext;
Expand Down Expand Up @@ -1601,10 +1602,11 @@ private void iterateClashingExprent(Statement stat, StructMethod mt, Map<Stateme

// Try to perform a rename
String name = mw.varproc.getVarName(vvp);
String original = name;
name = rename(nameMap, name);

// Did we rename? If so, we should add it to the name map and set as clashing
if (!mw.varproc.getVarName(vvp).equals(name)) {
if (original != null && !original.equals(name)) {
mw.varproc.setClashingName(vvp, name);
nameMap.put(new VarInMethod(vvp, mt2), name);
}
Expand Down Expand Up @@ -1653,10 +1655,11 @@ private void iterateClashingExprent(Statement stat, StructMethod mt, Map<Stateme

// Try to perform a rename
String name = mw.varproc.getVarName(vvp);
String original = name;
name = rename(nameMap, name);

// Did we rename? If so, we should add it to the name map and set as clashing
if (!mw.varproc.getVarName(vvp).equals(name)) {
if (original != null && !original.equals(name)) {
mw.varproc.setClashingName(vvp, name);
nameMap.put(new VarInMethod(vvp, mt2), name);
}
Expand Down Expand Up @@ -1756,7 +1759,7 @@ private void iterateClashingExprent(Statement stat, StructMethod mt, Map<Stateme
}
}

private static String rename(Map<VarInMethod, String> nameMap, String name) {
private static @NotNull String rename(Map<VarInMethod, String> nameMap, String name) {
while (nameMap.containsValue(name)) {
name += "x";
}
Expand Down

0 comments on commit c45692c

Please sign in to comment.