Skip to content

Replace a single Guava call causing dependency hell #1

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

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions src/main/java/com/github/fge/jackson/JsonLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package com.github.fge.jackson;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.io.Closer;

import javax.annotation.Nonnull;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static JsonNode fromResource(@Nonnull final String resource)
URL url;
url = JsonLoader.class.getResource(resource);
if (url == null) {
final ClassLoader classLoader = Objects.firstNonNull(
final ClassLoader classLoader = firstNonNull(
Thread.currentThread().getContextClassLoader(),
JsonLoader.class.getClassLoader()
);
Expand All @@ -104,6 +104,20 @@ public static JsonNode fromResource(@Nonnull final String resource)
return ret;
}

/**
* Returns the first non-null parameter.
*
* Implementation note: Avoids the Guava method of the same name, to mitigate 'Dependency Hell'.
* This can be replaced by {@code MoreObjects.firstNonNull} when moving to Guava >= 18.0
* (Tip: Guava 20 seems like a good choice if Java 6 support is still necessary.)
*
* @throws NullPointerException if both are null.
*/
private static ClassLoader firstNonNull(ClassLoader first, ClassLoader second)
{
return first != null ? first : Preconditions.checkNotNull(second);
}

/**
* Read a {@link JsonNode} from an URL.
*
Expand Down