Skip to content

Commit

Permalink
Fix possible ClassCastException in closeables composer
Browse files Browse the repository at this point in the history
  • Loading branch information
aNNiMON committed Aug 7, 2018
1 parent deaf1be commit 12ba844
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions stream/src/main/java/com/annimon/stream/internal/Compose.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ public void run() {
try {
b.run();
} catch (Throwable ignore) { }
if (e1 instanceof RuntimeException) {
throw (RuntimeException) e1;
}
throw (Error) e1;
handleException(e1);
return;
}
b.run();
}
Expand All @@ -36,23 +34,25 @@ public void run() {
try {
b.close();
} catch (Throwable ignore) { }
if (e1 instanceof RuntimeException) {
throw (RuntimeException) e1;
}
throw (Error) e1;
handleException(e1);
return;
}
try {
b.close();
} catch (Throwable e2) {
if (e2 instanceof RuntimeException) {
throw (RuntimeException) e2;
} else if (e2 instanceof Error) {
throw (Error) e2;
} else {
throw new RuntimeException(e2);
}
handleException(e2);
}
}
};
}

private static void handleException(Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else if (e instanceof Error) {
throw (Error) e;
} else {
throw new RuntimeException(e);
}
}
}

0 comments on commit 12ba844

Please sign in to comment.