Ensure RelocatorCommand builder fails with CompilationFailedException
Change-Id: Ib7561483b0cedbc2725d8453a592fb3df8b559fd
diff --git a/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java b/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java
index e329c4d..b8355c3 100644
--- a/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java
+++ b/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java
@@ -21,7 +21,9 @@
import com.android.tools.r8.shaking.ProguardPathList;
import com.android.tools.r8.utils.AbortException;
import com.android.tools.r8.utils.AndroidApp;
+import com.android.tools.r8.utils.Box;
import com.android.tools.r8.utils.ExceptionDiagnostic;
+import com.android.tools.r8.utils.ExceptionUtils;
import com.android.tools.r8.utils.FlagFile;
import com.android.tools.r8.utils.InternalOptions;
import com.android.tools.r8.utils.Reporter;
@@ -292,19 +294,23 @@
}
public RelocatorCommand build() throws CompilationFailedException {
- try {
- if (printHelp || printVersion) {
- return new RelocatorCommand(printHelp, printVersion);
- }
- reporter.failIfPendingErrors();
- validate();
- reporter.failIfPendingErrors();
- DexItemFactory factory = new DexItemFactory();
- return new RelocatorCommand(
- mapping.build(), app.build(), reporter, factory, consumer, threadCount);
- } catch (AbortException e) {
- throw new CompilationFailedException(e);
- }
+ Box<RelocatorCommand> result = new Box<>();
+ ExceptionUtils.withCompilationHandler(
+ reporter,
+ () -> {
+ if (printHelp || printVersion) {
+ result.set(new RelocatorCommand(printHelp, printVersion));
+ return;
+ }
+ reporter.failIfPendingErrors();
+ validate();
+ reporter.failIfPendingErrors();
+ DexItemFactory factory = new DexItemFactory();
+ result.set(
+ new RelocatorCommand(
+ mapping.build(), app.build(), reporter, factory, consumer, threadCount));
+ });
+ return result.get();
}
// Helper to signify an error.