Skip to content

Commit

Permalink
Guava Throwables deprecation warning (treasure-data#1604)
Browse files Browse the repository at this point in the history
* Create sub project digdag-commons and implement ThrowablesUtil
* Upgrade gradle to 6.8.3
* Upgrade JUnit to 4.13.2
* Upgrade guava version to `30.1.1-jre`
* Change assertThat from JUnit to Hamcrest to stop deprecation warning
  • Loading branch information
yoyama committed Jun 14, 2021
1 parent cf73572 commit 07c1178
Show file tree
Hide file tree
Showing 219 changed files with 601 additions and 534 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ subprojects {
annotationProcessor "org.immutables:value:2.3.9"
testAnnotationProcessor "org.immutables:value:2.3.9"

testCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.13.2'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'pl.pragmatists:JUnitParams:1.0.5'
Expand All @@ -83,7 +83,7 @@ subprojects {
jacksonVersion = "2.9.10"
jacksonDatabindVersion = "2.9.10"
awsJavaSdkVersion = "1.11.686"
guavaVersion = "19.0"
guavaVersion = "30.1.1-jre"
}

tasks.withType(JavaCompile) {
Expand Down Expand Up @@ -357,7 +357,7 @@ coveralls {

wrapper {
// Find the latest version at https://gradle.org/releases/
gradleVersion = '6.3'
gradleVersion = '6.8.3'
}

project(':digdag-ui') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.io.File;
import com.google.common.base.Throwables;
import io.digdag.commons.ThrowablesUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteStreams;

Expand Down Expand Up @@ -65,7 +65,7 @@ public void visualize(List<WorkflowVisualizerNode> nodes, File output)
generate(dot, output);
}
catch (IOException ex) {
throw Throwables.propagate(ex);
throw ThrowablesUtil.propagate(ex);
}
}

Expand All @@ -90,7 +90,7 @@ private void generate(String dot, File output)
}
catch (RuntimeException | IOException ex) {
// TODO uncaught exception
throw Throwables.propagate(ex);
throw ThrowablesUtil.propagate(ex);
}
});
t.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.digdag.cli;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -14,20 +13,18 @@
import java.nio.file.Path;
import javax.annotation.PreDestroy;

import io.digdag.commons.ThrowablesUtil;
import io.digdag.core.database.TransactionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.inject.Inject;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.digdag.core.session.ArchivedTask;
import io.digdag.core.session.StoredSessionAttemptWithSession;
import io.digdag.core.session.SessionStoreManager;
import io.digdag.core.session.TaskStateCode;
import io.digdag.core.workflow.Tasks;
import io.digdag.core.repository.ResourceNotFoundException;
import io.digdag.spi.TaskResult;
import io.digdag.spi.TaskReport;
import io.digdag.client.config.ConfigFactory;
Expand Down Expand Up @@ -65,7 +62,7 @@ TaskResult readSuccessfulTaskReport(Path dir, String fullName)
return null;
}
catch (IOException ex) {
throw Throwables.propagate(ex);
throw ThrowablesUtil.propagate(ex);
}
if (resumeState.getState() == TaskStateCode.SUCCESS) {
return resumeState.getResult();
Expand Down
4 changes: 2 additions & 2 deletions digdag-cli/src/main/java/io/digdag/cli/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.beust.jcommander.Parameter;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
Expand All @@ -13,6 +12,7 @@
import io.digdag.client.config.Config;
import io.digdag.client.config.ConfigException;
import io.digdag.client.config.ConfigFactory;
import io.digdag.commons.ThrowablesUtil;
import io.digdag.core.DigdagEmbed;
import io.digdag.core.Limits;
import io.digdag.core.LocalSite;
Expand Down Expand Up @@ -633,7 +633,7 @@ private static Optional<Instant> getLastSessionTime(Path sessionStatusPath, Stri
return Optional.absent();
}
catch (IOException ex) {
throw Throwables.propagate(ex);
throw ThrowablesUtil.propagate(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.digdag.client.DigdagClient;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class ClientBuildingTest
{
Expand Down
2 changes: 2 additions & 0 deletions digdag-client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

dependencies {
compile project(':digdag-commons')

compile 'javax.inject:javax.inject:1'
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:${project.ext.jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${project.ext.jacksonVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import io.digdag.client.api.Id;
import io.digdag.client.api.JacksonTimeModule;
Expand Down Expand Up @@ -46,6 +45,7 @@
import io.digdag.client.api.SessionTimeTruncate;
import io.digdag.client.config.Config;
import io.digdag.client.config.ConfigFactory;
import io.digdag.commons.ThrowablesUtil;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPFilter;
import org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor;
Expand Down Expand Up @@ -665,7 +665,7 @@ public RestLogFileHandleCollection getLogFileHandlesOfTask(Id attemptId, String

return doGet(RestLogFileHandleCollection.class, webTarget);
} catch (UnsupportedEncodingException ex) {
throw Throwables.propagate(ex);
throw ThrowablesUtil.propagate(ex);
}
}

Expand Down Expand Up @@ -725,7 +725,7 @@ private Response invokeWithRetry(Invocation request)
}
catch (ExecutionException | RetryException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
throw Throwables.propagate(cause);
throw ThrowablesUtil.propagate(cause);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.digdag.client;

import com.google.common.base.Throwables;
import com.google.common.io.Resources;
import io.digdag.commons.ThrowablesUtil;

import java.io.IOException;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand All @@ -27,7 +28,7 @@ private static String versionString()
return Resources.toString(Resources.getResource(Version.class, "version.txt"), UTF_8).trim();
}
catch (IOException e) {
throw Throwables.propagate(e);
throw ThrowablesUtil.propagate(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -19,6 +18,8 @@
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.core.type.TypeReference;
import io.digdag.commons.ThrowablesUtil;

import static java.util.Locale.ENGLISH;

public class Config
Expand Down Expand Up @@ -197,7 +198,7 @@ private JsonNode writeObject(Object obj)
return mapper.readTree(value);
}
catch (Exception ex) {
throw Throwables.propagate(ex);
throw ThrowablesUtil.propagate(ex);
}
}

Expand Down Expand Up @@ -497,7 +498,7 @@ private Object readObject(JavaType type, JsonNode value, String key)

private ConfigException propagateConvertException(Exception ex, String typeName, JsonNode value, String key)
{
Throwables.propagateIfInstanceOf(ex, ConfigException.class);
ThrowablesUtil.propagateIfInstanceOf(ex, ConfigException.class);
String message = String.format(ENGLISH, "Expected %s for key '%s' but got %s (%s)",
typeName, key, jsonSample(value), typeNameOf(value));
return new ConfigException(message, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static okhttp3.tls.internal.TlsUtil.localhost;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import org.junit.Test;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.hamcrest.MatcherAssert.assertThat;

public class VersionTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class IdTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.UUID;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static io.digdag.client.config.ConfigUtils.newConfig;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class ModelCompatibilityTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.junit.Test;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class SecretValidationTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.junit.Test;

import static org.junit.Assert.fail;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class ConfigKeyTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static io.digdag.client.config.ConfigUtils.newConfig;

public class ConfigTest
Expand Down
4 changes: 4 additions & 0 deletions digdag-commons/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

dependencies {
compile "com.google.guava:guava:${project.ext.guavaVersion}"
}
40 changes: 40 additions & 0 deletions digdag-commons/src/main/java/io/digdag/commons/ThrowablesUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.digdag.commons;

import com.google.common.base.Throwables;

public class ThrowablesUtil
{
/**
* Original code from com.google.common.base.Throwables.propagate
* This method is provided for reduce guava dependencies, suppress many warnings on deprecation.
* As the wiki describe, propagate() is not necessary in most of cases.
* So not use this method for new updated code.
* Reference: https://github.com/google/guava/wiki/Why-we-deprecated-Throwables.propagate
*/
public static RuntimeException propagate(Throwable throwable)
{
Throwables.throwIfUnchecked(throwable);
throw new RuntimeException(throwable);
}

/**
* Original code from com.google.common.base.Throwables.propagateIfInstanceOf
*/
public static <X extends Throwable> void propagateIfInstanceOf(Throwable throwable, Class<X> declaredType)
throws X
{
if (throwable != null) {
Throwables.throwIfInstanceOf(throwable, declaredType);
}
}

/**
* Original code from com.google.common.base.Throwables.propagateIfPossible
*/
public static void propagateIfPossible(Throwable throwable)
{
if (throwable != null) {
Throwables.throwIfUnchecked(throwable);
}
}
}
Loading

0 comments on commit 07c1178

Please sign in to comment.