You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2021/03/06 16:57:57 UTC
[asterixdb] 10/17: [NO ISSUE][HYR] Exception map utility method,
fix getBootClassPath() on java >= 9
This is an automated email from the ASF dual-hosted git repository.
mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 038a627bf799c6d02273e581559031e66429d24c
Author: Michael Blow <mi...@couchbase.com>
AuthorDate: Thu Mar 4 09:17:20 2021 -0500
[NO ISSUE][HYR] Exception map utility method, fix getBootClassPath() on java >= 9
Change-Id: Ic4cb7a6c3c3636578ba02584cebdba55e6da9995
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/10363
Reviewed-by: Michael Blow <mb...@apache.org>
Reviewed-by: Till Westmann <ti...@apache.org>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
---
hyracks-fullstack/hyracks/hyracks-api/pom.xml | 4 ++++
.../apache/hyracks/api/util/ExceptionUtils.java | 25 ++++++++++++++++++++++
.../java/org/apache/hyracks/util/MXHelper.java | 3 +--
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/hyracks-fullstack/hyracks/hyracks-api/pom.xml b/hyracks-fullstack/hyracks/hyracks-api/pom.xml
index 90fb5ed..2c50ee4 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/pom.xml
+++ b/hyracks-fullstack/hyracks/hyracks-api/pom.xml
@@ -94,5 +94,9 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
index 9067dce..d748ed8 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ExceptionUtils.java
@@ -21,9 +21,14 @@ package org.apache.hyracks.api.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
import org.apache.hyracks.api.exceptions.ErrorCode;
import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.util.ThrowingFunction;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
/**
* @author yingyib
@@ -133,4 +138,24 @@ public class ExceptionUtils {
public static boolean causedByInterrupt(Throwable th) {
return getRootCause(th) instanceof InterruptedException;
}
+
+ /**
+ * Convenience utility method to provide a form of {@link Map#computeIfAbsent(Object, Function)} which allows
+ * throwable mapping functions. Any exceptions thrown by the mapping function is propagated as an instance of
+ * {@link HyracksDataException}
+ */
+ public static <K, V> V computeIfAbsent(Map<K, V> map, K key, ThrowingFunction<K, V> function)
+ throws HyracksDataException {
+ try {
+ return map.computeIfAbsent(key, k -> {
+ try {
+ return function.process(k);
+ } catch (Exception e) {
+ throw new UncheckedExecutionException(e);
+ }
+ });
+ } catch (UncheckedExecutionException e) {
+ throw HyracksDataException.create(e.getCause());
+ }
+ }
}
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MXHelper.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MXHelper.java
index 247c001..c238b50 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MXHelper.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MXHelper.java
@@ -108,9 +108,8 @@ public class MXHelper {
public static String getBootClassPath() {
try {
- return runtimeMXBean.getBootClassPath();
+ return runtimeMXBean.isBootClassPathSupported() ? runtimeMXBean.getBootClassPath() : null;
} catch (UnsupportedOperationException e) {
- // boot classpath is not supported in Java 9 and later
LOGGER.debug("ignoring exception calling RuntimeMXBean.getBootClassPath; returning null", e);
return null;
}