From be21cb6f2946c1bd0545359b291167d0690c7e2d Mon Sep 17 00:00:00 2001 From: nharmata Date: Thu, 18 Jan 2018 12:02:48 -0800 Subject: Address post-commit comments in https://github.com/bazelbuild/bazel/commit/6f35e2d81a4d10359d39643bd03887d1b87f4224. RELNOTES: None PiperOrigin-RevId: 182415982 --- .../google/devtools/build/lib/vfs/UnixGlob.java | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java') diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java index b20df29483..9d9cf87ded 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java @@ -488,7 +488,9 @@ public final class UnixGlob { private final ThreadPoolExecutor executor; private final AtomicLong totalOps = new AtomicLong(0); private final AtomicLong pendingOps = new AtomicLong(0); - private final AtomicReference failure = new AtomicReference<>(); + private final AtomicReference ioException = new AtomicReference<>(); + private final AtomicReference runtimeException = new AtomicReference<>(); + private final AtomicReference error = new AtomicReference<>(); private volatile boolean canceled = false; GlobVisitor( @@ -584,6 +586,19 @@ public final class UnixGlob { return result; } + private Throwable getMostSeriousThrowableSoFar() { + if (error.get() != null) { + return error.get(); + } + if (runtimeException.get() != null) { + return runtimeException.get(); + } + if (ioException.get() != null) { + return ioException.get(); + } + return null; + } + /** Should only be called by link {@GlobTaskContext}. */ private void queueGlob(final Path base, final boolean baseIsDir, final int idx, final GlobTaskContext context) { @@ -593,8 +608,12 @@ public final class UnixGlob { Profiler.instance().startTask(ProfilerTask.VFS_GLOB, this); try { reallyGlob(base, baseIsDir, idx, context); - } catch (Throwable e) { - failure.set(e); + } catch (IOException e) { + ioException.set(e); + } catch (RuntimeException e) { + runtimeException.set(e); + } catch (Error e) { + error.set(e); } finally { Profiler.instance().completeTask(ProfilerTask.VFS_GLOB); } @@ -618,7 +637,7 @@ public final class UnixGlob { Runnable wrapped = () -> { try { - if (!canceled && failure.get() == null) { + if (!canceled && getMostSeriousThrowableSoFar() == null) { r.run(); } } finally { @@ -646,10 +665,12 @@ public final class UnixGlob { // We get to 0 iff we are done all the relevant work. This is because we always increment // the pending ops count as we're enqueuing, and don't decrement until the task is complete // (which includes accounting for any additional tasks that one enqueues). + + Throwable mostSeriousThrowable = getMostSeriousThrowableSoFar(); if (canceled) { result.markCanceled(); - } else if (failure.get() != null) { - result.setException(failure.get()); + } else if (mostSeriousThrowable != null) { + result.setException(mostSeriousThrowable); } else { result.set(ImmutableList.copyOf(results)); } -- cgit v1.2.3