2727import java .util .LinkedHashSet ;
2828import java .util .List ;
2929import java .util .Map ;
30+ import java .util .Optional ;
3031import java .util .Set ;
3132import proguard .classfile .Clazz ;
3233import proguard .classfile .Method ;
@@ -121,7 +122,10 @@ public DominatorCalculator(boolean ignoreExceptions) {
121122 * @param dominator The potentially dominating instruction's offset
122123 * @param inferior The potentially dominated instruction's offset
123124 * @return true if the potential dominator is indeed guaranteed to be executed before the inferior
125+ * @deprecated Callers should use {@link #maybeDominates} to handle an optional value instead of
126+ * an exception.
124127 */
128+ @ Deprecated
125129 public boolean dominates (int dominator , int inferior ) {
126130 BitSet dominators = dominatorMap .get (inferior );
127131 if (dominators == null ) {
@@ -134,6 +138,25 @@ public boolean dominates(int dominator, int inferior) {
134138 return dominators .get (offsetToIndex (dominator ));
135139 }
136140
141+ /**
142+ * Check if one instruction dominates another one. If this is the case, the dominating instruction
143+ * is guaranteed to be executed before the inferior instruction. Should you wish to check whether
144+ * an instruction is guaranteed to be executed once the containing method is invoked, you can use
145+ * the virtual inferior {@link #EXIT_NODE_OFFSET} as a collection for all return instructions.
146+ *
147+ * @param dominator The potentially dominating instruction's offset
148+ * @param inferior The potentially dominated instruction's offset
149+ * @return Optional.true if the potential dominator is indeed guaranteed to be executed before the
150+ * inferior, Optional.false if not and Optional.empty when no dominator information is known.
151+ */
152+ public Optional <Boolean > maybeDominates (int dominator , int inferior ) {
153+ BitSet dominators = dominatorMap .get (inferior );
154+ if (dominators == null ) {
155+ return Optional .empty ();
156+ }
157+ return Optional .of (dominators .get (offsetToIndex (dominator )));
158+ }
159+
137160 /**
138161 * As we introduced {@link #ENTRY_NODE_OFFSET} and {@link #EXIT_NODE_OFFSET} as virtual
139162 * instruction offsets, the rest of the instructions are shifted by those two places. In order to
0 commit comments