From ef62a733b9af16b21cc19788570206e130b90f04 Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sat, 18 Feb 2023 21:39:26 +0100 Subject: [PATCH] Remove org.apache.common Signed-off-by: lsiepel --- .../handler/WeatherCompanyBridgeHandler.java | 4 +- .../internal/util/ExceptionUtils.java | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/util/ExceptionUtils.java diff --git a/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyBridgeHandler.java b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyBridgeHandler.java index f030b3f9f170e..d4d316b958bd5 100644 --- a/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyBridgeHandler.java +++ b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyBridgeHandler.java @@ -16,11 +16,11 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpResponseException; import org.openhab.binding.weathercompany.internal.config.WeatherCompanyBridgeConfig; +import org.openhab.binding.weathercompany.internal.util.ExceptionUtils; import org.openhab.core.io.net.http.HttpUtil; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ChannelUID; @@ -58,7 +58,7 @@ public void run() { updateStatus(ThingStatus.ONLINE); cancelValidateApiKeyJob(); } catch (IOException e) { - Throwable rootcause = ExceptionUtils.getRootCause(e); + Throwable rootcause = ExceptionUtils.getRootThrowable(e); if (rootcause instanceof HttpResponseException && rootcause.getMessage().contains("Authentication challenge without")) { logger.debug("Bridge: HttpResponseException: API key is not valid"); diff --git a/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/util/ExceptionUtils.java b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/util/ExceptionUtils.java new file mode 100644 index 0000000000000..f2e322e528f2c --- /dev/null +++ b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/util/ExceptionUtils.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.weathercompany.internal.util; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * The {@link ExceptionUtils} class defines some static utility methods + * + * @author Leo Siepel - Initial contribution + */ +@NonNullByDefault +public class ExceptionUtils { + + public static @Nullable Throwable getRootThrowable(@Nullable Throwable throwable) { + List list = new ArrayList<>(); + while (throwable != null && !list.contains(throwable)) { + list.add(throwable); + throwable = throwable.getCause(); + } + return throwable; + } +}