Skip to content

Commit

Permalink
[FLINK-35158][Core/API] Move functional interfaces about consumers fr…
Browse files Browse the repository at this point in the history
…om core module to core-api
  • Loading branch information
Zakelly committed Apr 23, 2024
1 parent 0b2e988 commit 70229bc
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.flink.util.function;

import org.apache.flink.util.ExceptionUtils;

import java.util.function.BiConsumer;

/**
Expand Down Expand Up @@ -56,7 +54,7 @@ static <A, B> BiConsumer<A, B> unchecked(
try {
biConsumerWithException.accept(a, b);
} catch (Throwable t) {
ExceptionUtils.rethrow(t);
ThrowingExceptionUtils.rethrow(t);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.flink.util.function;

import org.apache.flink.util.ExceptionUtils;

import java.util.function.BiFunction;

/**
Expand Down Expand Up @@ -58,7 +56,7 @@ static <A, B, C> BiFunction<A, B, C> unchecked(
try {
return biFunctionWithException.apply(a, b);
} catch (Throwable t) {
ExceptionUtils.rethrow(t);
ThrowingExceptionUtils.rethrow(t);
// we need this to appease the compiler :-(
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.flink.util.function;

import org.apache.flink.util.FlinkException;

import java.util.function.Supplier;

/** Similar to {@link java.util.function.Supplier} but can throw {@link Exception}. */
Expand All @@ -41,7 +39,7 @@ static <R> CheckedSupplier<R> checked(Supplier<R> supplier) {
try {
return supplier.get();
} catch (RuntimeException e) {
throw new FlinkException(e);
throw new Exception(e);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.flink.util.function;

/** Exception utils only for this package. */
class ThrowingExceptionUtils {

/**
* Throws the given {@code Throwable} in scenarios where the signatures do not allow you to
* throw an arbitrary Throwable. Errors and RuntimeExceptions are thrown directly, other
* exceptions are packed into runtime exceptions
*
* @param t The throwable to be thrown.
*/
static void rethrow(Throwable t) {
if (t instanceof Error) {
throw (Error) t;
} else if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else {
throw new RuntimeException(t);
}
}

private ThrowingExceptionUtils() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.flink.util.function;

import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.util.ExceptionUtils;

/**
* Similar to a {@link Runnable}, this interface is used to capture a block of code to be executed.
Expand Down Expand Up @@ -48,7 +47,7 @@ static Runnable unchecked(ThrowingRunnable<?> throwingRunnable) {
try {
throwingRunnable.run();
} catch (Throwable t) {
ExceptionUtils.rethrow(t);
ThrowingExceptionUtils.rethrow(t);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.flink.util.function;

import org.apache.flink.util.ExceptionUtils;

/**
* A checked extension of the {@link TriConsumer} interface.
*
Expand Down Expand Up @@ -57,7 +55,7 @@ static <A, B, C> TriConsumer<A, B, C> unchecked(
try {
triConsumerWithException.accept(a, b, c);
} catch (Throwable t) {
ExceptionUtils.rethrow(t);
ThrowingExceptionUtils.rethrow(t);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.flink.util.function;

import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.util.ExceptionUtils;

import java.util.function.BiFunction;

Expand Down Expand Up @@ -63,7 +62,7 @@ static <A, B, C, D> TriFunction<A, B, C, D> unchecked(
try {
return triFunctionWithException.apply(a, b, c);
} catch (Throwable t) {
ExceptionUtils.rethrow(t);
ThrowingExceptionUtils.rethrow(t);
// we need this to appease the compiler :-(
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,12 @@ under the License.
<!-- MARKER: start exclusions; these will be wiped by tools/releasing/update_japicmp_configuration.sh -->
<exclude>org.apache.flink.api.common.functions.Function</exclude>
<exclude>org.apache.flink.api.java.functions.KeySelector</exclude>
<exclude>org.apache.flink.util.function.FunctionWithException</exclude>
<exclude>org.apache.flink.util.function.LongFunctionWithException</exclude>
<exclude>org.apache.flink.util.function.RunnableWithException</exclude>
<exclude>org.apache.flink.util.function.SerializableFunction</exclude>
<exclude>org.apache.flink.util.function.SupplierWithException</exclude>
<exclude>org.apache.flink.util.function.ThrowingConsumer</exclude>
<!-- MARKER: end exclusions -->
</excludes>
<accessModifier>public</accessModifier>
Expand Down

0 comments on commit 70229bc

Please sign in to comment.