1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.bcel.generic;
20
21 /**
22 * Thrown by {@link InstructionList} when one or multiple disposed instructions are still being referenced by an {@link InstructionTargeter} object. I.e. the
23 * {@link InstructionTargeter} has to be notified that (one of) the {@link InstructionHandle} it is referencing is being removed from the
24 * {@link InstructionList} and thus not valid anymore.
25 *
26 * <p>
27 * Making this an exception instead of a return value forces the user to handle these case explicitly in a try { ... } catch. The following code illustrates how
28 * this may be done:
29 * </p>
30 *
31 * <pre>
32 * ...
33 * try {
34 * il.delete(start_ih, end_ih);
35 * } catch (TargetLostException e) {
36 * for (InstructionHandle target : e.getTargets()) {
37 * for (InstructionTargeter targeter : target.getTargeters()) {
38 * targeter.updateTarget(target, new_target);
39 * }
40 * }
41 * }
42 * </pre>
43 *
44 * @see InstructionHandle
45 * @see InstructionList
46 * @see InstructionTargeter
47 */
48 public final class TargetLostException extends Exception {
49
50 private static final long serialVersionUID = -6857272667645328384L;
51 private final InstructionHandle[] targets;
52
53 TargetLostException(final InstructionHandle[] targets, final String message) {
54 super(message);
55 this.targets = targets;
56 }
57
58 /**
59 * Gets the list of instructions still being targeted.
60 *
61 * @return list of instructions still being targeted.
62 */
63 public InstructionHandle[] getTargets() {
64 return targets;
65 }
66 }