■ ■ ■ ■ ■ ■
jadx-core/src/main/java/jadx/core/dex/trycatch/TryCatchBlock.java
| skipped 14 lines |
15 | 15 | | import java.util.ArrayList; |
16 | 16 | | import java.util.Collection; |
17 | 17 | | import java.util.Collections; |
| 18 | + | import java.util.Iterator; |
| 19 | + | import java.util.LinkedList; |
18 | 20 | | import java.util.List; |
19 | 21 | | |
20 | 22 | | public class TryCatchBlock { |
| skipped 6 lines |
27 | 29 | | private final CatchAttr attr; |
28 | 30 | | |
29 | 31 | | public TryCatchBlock() { |
30 | | - | handlers = new ArrayList<ExceptionHandler>(2); |
| 32 | + | handlers = new LinkedList<ExceptionHandler>(); |
31 | 33 | | insns = new ArrayList<InsnNode>(); |
32 | 34 | | attr = new CatchAttr(this); |
33 | 35 | | } |
| skipped 11 lines |
45 | 47 | | } |
46 | 48 | | |
47 | 49 | | public void removeHandler(MethodNode mth, ExceptionHandler handler) { |
48 | | - | for (int i = 0; i < handlers.size(); i++) { |
49 | | - | if (handlers.get(i) == handler) { |
50 | | - | handlers.remove(i); |
| 50 | + | for (Iterator<ExceptionHandler> it = handlers.iterator(); it.hasNext(); ) { |
| 51 | + | ExceptionHandler h = it.next(); |
| 52 | + | if (h == handler) { |
| 53 | + | it.remove(); |
51 | 54 | | break; |
52 | 55 | | } |
53 | 56 | | } |
| skipped 16 lines |
70 | 73 | | } |
71 | 74 | | } |
72 | 75 | | } |
73 | | - | return; |
| 76 | + | } else { |
| 77 | + | // self destruction |
| 78 | + | for (InsnNode insn : insns) { |
| 79 | + | insn.getAttributes().remove(attr); |
| 80 | + | } |
| 81 | + | insns.clear(); |
| 82 | + | for (BlockNode block : mth.getBasicBlocks()) { |
| 83 | + | block.getAttributes().remove(attr); |
| 84 | + | } |
74 | 85 | | } |
75 | | - | |
76 | | - | // self destruction |
77 | | - | for (InsnNode insn : insns) |
78 | | - | insn.getAttributes().remove(attr); |
79 | | - | |
80 | | - | insns.clear(); |
81 | | - | for (BlockNode block : mth.getBasicBlocks()) |
82 | | - | block.getAttributes().remove(attr); |
83 | 86 | | } |
84 | 87 | | |
85 | 88 | | public void addInsn(InsnNode insn) { |
| skipped 27 lines |
113 | 116 | | } |
114 | 117 | | |
115 | 118 | | public void setFinalBlockFromInsns(MethodNode mth, List<InsnNode> insns) { |
116 | | - | InsnContainer cont = new InsnContainer(); |
117 | 119 | | List<InsnNode> finalBlockInsns = new ArrayList<InsnNode>(insns); |
118 | | - | cont.setInstructions(finalBlockInsns); |
119 | | - | setFinalBlock(cont); |
| 120 | + | setFinalBlock(new InsnContainer(finalBlockInsns)); |
120 | 121 | | |
121 | 122 | | InstructionRemover.unbindInsnList(finalBlockInsns); |
122 | 123 | | |
123 | 124 | | // remove these instructions from other handlers |
124 | 125 | | for (ExceptionHandler h : getHandlers()) { |
125 | | - | for (BlockNode ehb : h.getBlocks()) |
| 126 | + | for (BlockNode ehb : h.getBlocks()) { |
126 | 127 | | ehb.getInstructions().removeAll(finalBlockInsns); |
| 128 | + | } |
127 | 129 | | } |
128 | 130 | | // remove from blocks with this catch |
129 | 131 | | for (BlockNode b : mth.getBasicBlocks()) { |
130 | 132 | | IAttribute ca = b.getAttributes().get(AttributeType.CATCH_BLOCK); |
131 | | - | if (attr == ca) |
| 133 | + | if (attr == ca) { |
132 | 134 | | b.getInstructions().removeAll(finalBlockInsns); |
| 135 | + | } |
133 | 136 | | } |
134 | 137 | | } |
135 | 138 | | |
136 | 139 | | public void merge(MethodNode mth, TryCatchBlock tryBlock) { |
137 | | - | for (InsnNode insn : tryBlock.getInsns()) |
| 140 | + | for (InsnNode insn : tryBlock.getInsns()) { |
138 | 141 | | this.addInsn(insn); |
139 | | - | |
| 142 | + | } |
140 | 143 | | this.handlers.addAll(tryBlock.getHandlers()); |
141 | | - | for (ExceptionHandler eh : handlers) |
| 144 | + | for (ExceptionHandler eh : handlers) { |
142 | 145 | | eh.setTryBlock(this); |
143 | | - | |
| 146 | + | } |
144 | 147 | | // clear |
145 | 148 | | tryBlock.handlers.clear(); |
146 | 149 | | tryBlock.removeWholeBlock(mth); |
| skipped 1 lines |
148 | 151 | | |
149 | 152 | | @Override |
150 | 153 | | public int hashCode() { |
151 | | - | final int prime = 31; |
152 | | - | int result = 1; |
153 | | - | result = prime * result + ((handlers == null) ? 0 : handlers.hashCode()); |
154 | | - | return result; |
| 154 | + | return handlers.hashCode(); |
155 | 155 | | } |
156 | 156 | | |
157 | 157 | | @Override |
158 | 158 | | public boolean equals(Object obj) { |
159 | | - | if (this == obj) return true; |
160 | | - | if (obj == null) return false; |
161 | | - | if (getClass() != obj.getClass()) return false; |
| 159 | + | if (this == obj) { |
| 160 | + | return true; |
| 161 | + | } |
| 162 | + | if (obj == null || getClass() != obj.getClass()) { |
| 163 | + | return false; |
| 164 | + | } |
162 | 165 | | TryCatchBlock other = (TryCatchBlock) obj; |
163 | | - | if (!handlers.equals(other.handlers)) return false; |
164 | | - | return true; |
| 166 | + | return handlers.equals(other.handlers); |
165 | 167 | | } |
166 | 168 | | |
167 | 169 | | @Override |
168 | 170 | | public String toString() { |
169 | 171 | | return "Catch:{ " + Utils.listToString(handlers) + " }"; |
170 | 172 | | } |
171 | | - | |
172 | 173 | | } |
173 | 174 | | |