package aQute.lib.exceptions;

public class Exceptions {
	private Exceptions() {}
	public static RuntimeException duck(Throwable t) {
		Exceptions.<RuntimeException> throwsUnchecked(t);
		throw new AssertionError("unreachable");
	}

	@SuppressWarnings("unchecked")
	private static <E extends Throwable> void throwsUnchecked(Throwable throwable) throws E {
		throw (E) throwable;
	}

	public static Runnable wrap(final RunnableWithException run) {
		return new Runnable() {

			@Override
			public void run() {
				try {
					run.run();
				} catch (Exception e) {
					throw duck(e);
				}
			}

		};
	}

	public static <T, R> org.osgi.util.function.Function<T,R> wrap(final FunctionWithException<T,R> run) {
		return new org.osgi.util.function.Function<T,R>() {

			@Override
			public R apply(T value) {
				try {
					return run.apply(value);
				} catch (Exception e) {
					throw duck(e);
				}
			}
		};
	}

}

package aQute.lib.exceptions;

public class Exceptions {
	static RuntimeException singleton = new RuntimeException();

	public static RuntimeException duck(Throwable t) {
		Exceptions.<RuntimeException> asUncheckedException0(t);
		return singleton;
	}

	@SuppressWarnings("unchecked")
	private static <E extends Throwable> E asUncheckedException0(Throwable throwable) throws E {
		return (E) throwable;
	}

	public static Runnable wrap(final RunnableWithException run) {
		return new Runnable() {

			@Override
			public void run() {
				try {
					run.run();
				} catch (Exception e) {
					duck(e);
				}
			}

		};
	}

	public static <T, R> org.osgi.util.function.Function<T,R> wrap(final FunctionWithException<T,R> run) {
		return new org.osgi.util.function.Function<T,R>() {

			@Override
			public R apply(T value) {
				try {
					return run.apply(value);
				} catch (Exception e) {
					duck(e);
					return null; // will never happen
				}
			}
		};
	}

}

--- 
+++ 
@@ -1,16 +1,15 @@
 package aQute.lib.exceptions;
 
 public class Exceptions {
-	static RuntimeException singleton = new RuntimeException();
-
+	private Exceptions() {}
 	public static RuntimeException duck(Throwable t) {
-		Exceptions.<RuntimeException> asUncheckedException0(t);
-		return singleton;
+		Exceptions.<RuntimeException> throwsUnchecked(t);
+		throw new AssertionError("unreachable");
 	}
 
 	@SuppressWarnings("unchecked")
-	private static <E extends Throwable> E asUncheckedException0(Throwable throwable) throws E {
-		return (E) throwable;
+	private static <E extends Throwable> void throwsUnchecked(Throwable throwable) throws E {
+		throw (E) throwable;
 	}
 
 	public static Runnable wrap(final RunnableWithException run) {
@@ -21,7 +20,7 @@
 				try {
 					run.run();
 				} catch (Exception e) {
-					duck(e);
+					throw duck(e);
 				}
 			}
 
@@ -36,8 +35,7 @@
 				try {
 					return run.apply(value);
 				} catch (Exception e) {
-					duck(e);
-					return null; // will never happen
+					throw duck(e);
 				}
 			}
 		};
duck: Fix so it actually throws the ducked exception

Signed-off-by: BJ Hargrave <3d26bb3930946e3370762d769a073cece444c2d8@bjhargrave.com>
