diff --git a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java index 5e7027960..134d188ae 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java @@ -397,13 +397,12 @@ public class MethodGen { for (IDexTreeVisitor visitor : Jadx.getFallbackPassesList()) { DepthTraversal.visit(visitor, mth); } - errors.forEach(err -> mth.addAttr(AType.JADX_ERROR, err)); } catch (Exception e) { LOG.error("Error reload instructions in fallback mode:", e); code.startLine("// Can't load method instructions: " + e.getMessage()); return; } finally { - errors.forEach(err -> mth.addAttr(AType.JADX_ERROR, err)); + mth.addAttr(AType.JADX_ERROR, errors); } } InsnNode[] insnArr = mth.getInstructions(); diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java index 4c1fdc33c..ebbf69c84 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java @@ -12,10 +12,16 @@ public class AttrList implements IJadxAttribute { private static final int MAX_ATTRLIST_LENGTH = 300; private final IJadxAttrType> type; - private final List list = new ArrayList<>(); + private final List list; + + public AttrList(IJadxAttrType> type, List attrList) { + this.type = type; + this.list = attrList; + } public AttrList(IJadxAttrType> type) { this.type = type; + this.list = new ArrayList<>(); } public List getList() { diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java index ffc1e8b4d..577ee9ec1 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java @@ -50,8 +50,7 @@ public abstract class AttrNode implements IAttributeNode { } public void addAttr(IJadxAttrType> type, List list) { - AttributeStorage strg = initStorage(); - list.forEach(attr -> strg.add(type, attr)); + initStorage().addAttrList(type, list); } @Override diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeStorage.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeStorage.java index 049dfd105..d77a63735 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeStorage.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeStorage.java @@ -14,6 +14,7 @@ import jadx.api.plugins.input.data.attributes.IJadxAttrType; import jadx.api.plugins.input.data.attributes.IJadxAttribute; import jadx.api.plugins.input.data.attributes.JadxAttrType; import jadx.api.plugins.input.data.attributes.types.AnnotationsAttr; +import jadx.core.utils.ListUtils; import jadx.core.utils.Utils; import jadx.core.utils.exceptions.JadxRuntimeException; @@ -62,11 +63,20 @@ public class AttributeStorage { public void add(IJadxAttrType> type, T obj) { AttrList list = get(type); - if (list == null) { - list = new AttrList<>(type); - add(list); + if (list != null) { + list.getList().add(obj); + } else { + add(new AttrList<>(type, ListUtils.mutableListOf(obj))); + } + } + + public void addAttrList(IJadxAttrType> type, List attrList) { + AttrList list = get(type); + if (list != null) { + list.getList().addAll(attrList); + } else { + add(new AttrList<>(type, attrList)); } - list.getList().add(obj); } public void addAll(AttributeStorage otherList) { diff --git a/jadx-core/src/main/java/jadx/core/utils/ListUtils.java b/jadx-core/src/main/java/jadx/core/utils/ListUtils.java index be346a42f..fa0333f2d 100644 --- a/jadx-core/src/main/java/jadx/core/utils/ListUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/ListUtils.java @@ -19,6 +19,25 @@ import org.jetbrains.annotations.Nullable; public class ListUtils { + public static List mutableListOf(T obj) { + List list = new ArrayList<>(); + list.add(obj); + return list; + } + + public static List mutableListOf(T obj1, T obj2) { + List list = new ArrayList<>(); + list.add(obj1); + list.add(obj2); + return list; + } + + public static List mutableListOf(T... objs) { + List list = new ArrayList<>(); + Collections.addAll(list, objs); + return list; + } + public static boolean isSingleElement(@Nullable List list, T obj) { if (list == null || list.size() != 1) { return false;