Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed Checked* interfaces to declare to throw Exception instead of Throwable #2162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vavr/generator/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1570,9 +1570,9 @@ def generateMainClasses(): Unit = {
* Applies this function to ${arguments(i)} and returns the result.
${(0 to i).gen(j => if (j == 0) "*" else s"* @param t$j argument $j")("\n")}
* @return the result of function application
* ${checked.gen("@throws Throwable if something goes wrong applying this function to the given arguments")}
* ${checked.gen("@throws Exception if something goes wrong applying this function to the given arguments")}
*/
R apply($paramsDecl)${checked.gen(" throws Throwable")};
R apply($paramsDecl)${checked.gen(" throws Exception")};

${(1 until i).gen(j => {
val partialApplicationArgs = (1 to j).gen(k => s"T$k t$k")(", ")
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction0.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ static <R> CheckedFunction0<R> narrow(CheckedFunction0<? extends R> f) {
* Applies this function to no arguments and returns the result.
*
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply() throws Throwable;
R apply() throws Exception;

@Override
default int arity() {
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction1.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ static <T> CheckedFunction1<T, T> identity() {
*
* @param t1 argument 1
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1) throws Throwable;
R apply(T1 t1) throws Exception;

@Override
default int arity() {
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction2.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ static <T1, T2, R> CheckedFunction2<T1, T2, R> narrow(CheckedFunction2<? super T
* @param t1 argument 1
* @param t2 argument 2
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1, T2 t2) throws Throwable;
R apply(T1 t1, T2 t2) throws Exception;

/**
* Applies this function partially to one argument.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction3.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ static <T1, T2, T3, R> CheckedFunction3<T1, T2, T3, R> narrow(CheckedFunction3<?
* @param t2 argument 2
* @param t3 argument 3
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1, T2 t2, T3 t3) throws Throwable;
R apply(T1 t1, T2 t2, T3 t3) throws Exception;

/**
* Applies this function partially to one argument.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction4.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ static <T1, T2, T3, T4, R> CheckedFunction4<T1, T2, T3, T4, R> narrow(CheckedFun
* @param t3 argument 3
* @param t4 argument 4
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable;
R apply(T1 t1, T2 t2, T3 t3, T4 t4) throws Exception;

/**
* Applies this function partially to one argument.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction5.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ static <T1, T2, T3, T4, T5, R> CheckedFunction5<T1, T2, T3, T4, T5, R> narrow(Ch
* @param t4 argument 4
* @param t5 argument 5
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Throwable;
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Exception;

/**
* Applies this function partially to one argument.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction6.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ static <T1, T2, T3, T4, T5, T6, R> CheckedFunction6<T1, T2, T3, T4, T5, T6, R> n
* @param t5 argument 5
* @param t6 argument 6
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) throws Throwable;
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) throws Exception;

/**
* Applies this function partially to one argument.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction7.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ static <T1, T2, T3, T4, T5, T6, T7, R> CheckedFunction7<T1, T2, T3, T4, T5, T6,
* @param t6 argument 6
* @param t7 argument 7
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) throws Throwable;
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) throws Exception;

/**
* Applies this function partially to one argument.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src-gen/main/java/io/vavr/CheckedFunction8.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ static <T1, T2, T3, T4, T5, T6, T7, T8, R> CheckedFunction8<T1, T2, T3, T4, T5,
* @param t7 argument 7
* @param t8 argument 8
* @return the result of function application
* @throws Throwable if something goes wrong applying this function to the given arguments
* @throws Exception if something goes wrong applying this function to the given arguments
*/
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) throws Throwable;
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) throws Exception;

/**
* Applies this function partially to one argument.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src/main/java/io/vavr/CheckedConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public interface CheckedConsumer<T> {
* Performs side-effects.
*
* @param t a value of type {@code T}
* @throws Throwable if an error occurs
* @throws Exception if an error occurs
*/
void accept(T t) throws Throwable;
void accept(T t) throws Exception;

/**
* Returns a chained {@code CheckedConsumer} that first executes {@code this.accept(t)}
Expand Down
4 changes: 2 additions & 2 deletions vavr/src/main/java/io/vavr/CheckedPredicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public interface CheckedPredicate<T> {
*
* @param t the input argument
* @return {@code true} if the input argument matches the predicate, otherwise {@code false}
* @throws Throwable if an error occurs
* @throws Exception if an error occurs
*/
boolean test(T t) throws Throwable;
boolean test(T t) throws Exception;

/**
* Negates this predicate.
Expand Down
4 changes: 2 additions & 2 deletions vavr/src/main/java/io/vavr/CheckedRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface CheckedRunnable {
/**
* Performs side-effects.
*
* @throws Throwable if an error occurs
* @throws Exception if an error occurs
*/
void run() throws Throwable;
void run() throws Exception;
}
9 changes: 8 additions & 1 deletion vavr/src/test/java/io/vavr/concurrent/Concurrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ static <T> CheckedFunction0<T> zZz(T value) {
};
}

static <T, X extends Throwable> CheckedFunction0<T> zZz(X exception) {
static <T, X extends Exception> CheckedFunction0<T> zZz(X exception) {
return () -> {
zZz();
throw exception;
};
}

static <T, X extends Error> CheckedFunction0<T> zZz(X error) {
return () -> {
zZz();
throw error;
};
}
}
6 changes: 3 additions & 3 deletions vavr/src/test/java/io/vavr/concurrent/FutureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1151,14 +1151,14 @@ private static Future<Void> blocking(CheckedRunnable computation) {
private static <T> Future<T> blocking(CheckedFunction0<? extends T> computation) {
return Future.of(() -> {
final AtomicReference<T> result = new AtomicReference<>(null);
final AtomicReference<Throwable> errorRef = new AtomicReference<>(null);
final AtomicReference<Exception> errorRef = new AtomicReference<>(null);
ForkJoinPool.managedBlock(new ForkJoinPool.ManagedBlocker() {
boolean releasable = false;
@Override
public boolean block() throws InterruptedException {
try {
result.set(computation.apply());
} catch(Throwable x) {
} catch(Exception x) {
errorRef.set(x);
}
return releasable = true;
Expand All @@ -1168,7 +1168,7 @@ public boolean isReleasable() {
return releasable;
}
});
final Throwable error = errorRef.get();
final Exception error = errorRef.get();
if (error != null) {
throw error;
} else {
Expand Down
2 changes: 1 addition & 1 deletion vavr/src/test/java/io/vavr/control/TryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ public void shouldReturnRecoveredValueOnFailure(){

@Test
public void shouldNotRecoverFailureWhenExceptionTypeIsntAssignable(){
final Throwable error = new IllegalStateException(FAILURE);
final Exception error = new IllegalStateException(FAILURE);
assertThat(Try.of(() -> { throw error; }).recoverWith(Error.class, success()).getCause()).isSameAs(error);
}

Expand Down