Skip to content

Commit f36641a

Browse files
committed
Remove Guava. Build and tests now run on Java 6-11.
1 parent ce6f3a8 commit f36641a

23 files changed

+796
-147
lines changed

project.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ targetCompatibility = JavaVersion.VERSION_1_7; // defaults to sourceCompatibilit
3030
*/
3131
dependencies {
3232
implementation(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.9.9");
33-
implementation(group: "com.google.guava", name: "guava", version: "28.1-android");
3433
implementation(group: "com.github.java-json-tools", name: "msg-simple", version: "1.2-SNAPSHOT");
35-
implementation(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1");
34+
implementation(group: "com.google.code.findbugs", name: "jsr305", version: "3.0.2");
3635
testImplementation(group: "org.testng", name: "testng", version: "6.8.7") {
3736
exclude(group: "junit", module: "junit");
3837
exclude(group: "org.beanshell", module: "bsh");
@@ -49,9 +48,8 @@ javadoc {
4948
addStringOption("-release", "7");
5049
}
5150
links("https://docs.oracle.com/javase/7/docs/api/");
52-
links("https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.1/");
53-
links("https://fasterxml.github.io/jackson-databind/javadoc/2.2.0/");
54-
links("https://www.javadoc.io/doc/com.google.guava/guava/28.1-android/");
51+
links("https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/");
52+
links("https://fasterxml.github.io/jackson-databind/javadoc/2.9/");
5553
links("https://java-json-tools.github.io/msg-simple/");
5654
}
5755
}

src/main/java/com/github/fge/jackson/JacksonUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
import com.fasterxml.jackson.databind.ObjectWriter;
3030
import com.fasterxml.jackson.databind.SerializationFeature;
3131
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
32-
import com.google.common.collect.Maps;
3332

3433
import java.io.IOException;
3534
import java.io.StringWriter;
35+
import java.util.Collections;
36+
import java.util.HashMap;
3637
import java.util.Iterator;
3738
import java.util.Map;
3839

@@ -94,11 +95,11 @@ public static JsonNodeFactory nodeFactory()
9495
*/
9596
public static Map<String, JsonNode> asMap(final JsonNode node)
9697
{
97-
final Map<String, JsonNode> ret = Maps.newHashMap();
9898
if (!node.isObject())
99-
return ret;
99+
return Collections.emptyMap();
100100

101101
final Iterator<Map.Entry<String, JsonNode>> iterator = node.fields();
102+
final Map<String, JsonNode> ret = new HashMap<>();
102103

103104
Map.Entry<String, JsonNode> entry;
104105

@@ -107,7 +108,7 @@ public static Map<String, JsonNode> asMap(final JsonNode node)
107108
ret.put(entry.getKey(), entry.getValue());
108109
}
109110

110-
return ret;
111+
return Collections.unmodifiableMap(ret);
111112
}
112113

113114
/**

src/main/java/com/github/fge/jackson/JsonLoader.java

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
package com.github.fge.jackson;
2121

2222
import com.fasterxml.jackson.databind.JsonNode;
23-
import com.google.common.base.Preconditions;
24-
import com.google.common.io.Closer;
2523

2624
import javax.annotation.Nonnull;
27-
2825
import java.io.File;
2926
import java.io.FileInputStream;
3027
import java.io.IOException;
@@ -74,50 +71,44 @@ private JsonLoader()
7471
public static JsonNode fromResource(@Nonnull final String resource)
7572
throws IOException
7673
{
77-
Preconditions.checkNotNull(resource);
78-
Preconditions.checkArgument(resource.startsWith("/"),
79-
"resource path does not start with a '/'");
74+
if (resource == null) {
75+
throw new NullPointerException();
76+
}
77+
if (!resource.startsWith("/")) {
78+
throw new IllegalArgumentException("resource path does not start with a '/'");
79+
}
8080
URL url;
8181
url = JsonLoader.class.getResource(resource);
8282
if (url == null) {
83-
final ClassLoader classLoader = firstNonNull(
84-
Thread.currentThread().getContextClassLoader(),
85-
JsonLoader.class.getClassLoader()
86-
);
83+
final ClassLoader classLoader;
84+
if (Thread.currentThread().getContextClassLoader() != null) {
85+
classLoader = Thread.currentThread().getContextClassLoader();
86+
} else if (JsonLoader.class.getClassLoader() != null) {
87+
classLoader = JsonLoader.class.getClassLoader();
88+
} else {
89+
throw new NullPointerException();
90+
}
8791
final String s = INITIAL_SLASH.matcher(resource).replaceFirst("");
8892
url = classLoader.getResource(s);
8993
}
9094
if (url == null)
9195
throw new IOException("resource " + resource + " not found");
9296

93-
final Closer closer = Closer.create();
9497
final JsonNode ret;
95-
final InputStream in;
98+
InputStream in = null;
9699

97100
try {
98-
in = closer.register(url.openStream());
101+
in = url.openStream();
99102
ret = READER.fromInputStream(in);
100103
} finally {
101-
closer.close();
104+
if (in != null) {
105+
in.close();
106+
}
102107
}
103108

104109
return ret;
105110
}
106111

107-
/**
108-
* Returns the first non-null parameter.
109-
*
110-
* Implementation note: Avoids the Guava method of the same name, to mitigate 'Dependency Hell'.
111-
* This can be replaced by {@code MoreObjects.firstNonNull} when moving to Guava >= 18.0
112-
* (Tip: Guava 20 seems like a good choice if Java 6 support is still necessary.)
113-
*
114-
* @throws NullPointerException if both are null.
115-
*/
116-
private static ClassLoader firstNonNull(ClassLoader first, ClassLoader second)
117-
{
118-
return first != null ? first : Preconditions.checkNotNull(second);
119-
}
120-
121112
/**
122113
* Read a {@link JsonNode} from an URL.
123114
*
@@ -141,15 +132,16 @@ public static JsonNode fromURL(final URL url)
141132
public static JsonNode fromPath(final String path)
142133
throws IOException
143134
{
144-
final Closer closer = Closer.create();
145135
final JsonNode ret;
146-
final FileInputStream in;
136+
FileInputStream in = null;
147137

148138
try {
149-
in = closer.register(new FileInputStream(path));
139+
in = new FileInputStream(path);
150140
ret = READER.fromInputStream(in);
151141
} finally {
152-
closer.close();
142+
if (in != null) {
143+
in.close();
144+
}
153145
}
154146

155147
return ret;
@@ -166,15 +158,16 @@ public static JsonNode fromPath(final String path)
166158
public static JsonNode fromFile(final File file)
167159
throws IOException
168160
{
169-
final Closer closer = Closer.create();
170161
final JsonNode ret;
171-
final FileInputStream in;
162+
FileInputStream in = null;
172163

173164
try {
174-
in = closer.register(new FileInputStream(file));
165+
in = new FileInputStream(file);
175166
ret = READER.fromInputStream(in);
176167
} finally {
177-
closer.close();
168+
if (in != null) {
169+
in.close();
170+
}
178171
}
179172

180173
return ret;

src/main/java/com/github/fge/jackson/JsonNodeReader.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.github.fge.Builder;
3131
import com.github.fge.msgsimple.bundle.MessageBundle;
3232
import com.github.fge.msgsimple.bundle.PropertiesBundle;
33-
import com.google.common.io.Closer;
3433

3534
import javax.annotation.Nonnull;
3635
import javax.annotation.concurrent.ThreadSafe;
@@ -93,16 +92,20 @@ public JsonNodeReader()
9392
public JsonNode fromInputStream(final InputStream in)
9493
throws IOException
9594
{
96-
final Closer closer = Closer.create();
97-
final JsonParser parser;
98-
final MappingIterator<JsonNode> iterator;
95+
JsonParser parser = null;
96+
MappingIterator<JsonNode> iterator = null;
9997

10098
try {
101-
parser = closer.register(reader.getFactory().createParser(in));
99+
parser = reader.getFactory().createParser(in);
102100
iterator = reader.readValues(parser);
103-
return readNode(closer.register(iterator));
101+
return readNode(iterator);
104102
} finally {
105-
closer.close();
103+
if (parser != null) {
104+
parser.close();
105+
}
106+
if (iterator != null) {
107+
iterator.close();
108+
}
106109
}
107110
}
108111

@@ -117,16 +120,20 @@ public JsonNode fromInputStream(final InputStream in)
117120
public JsonNode fromReader(final Reader r)
118121
throws IOException
119122
{
120-
final Closer closer = Closer.create();
121-
final JsonParser parser;
122-
final MappingIterator<JsonNode> iterator;
123+
JsonParser parser = null;
124+
MappingIterator<JsonNode> iterator = null;
123125

124126
try {
125-
parser = closer.register(reader.getFactory().createParser(r));
127+
parser = reader.getFactory().createParser(r);
126128
iterator = reader.readValues(parser);
127-
return readNode(closer.register(iterator));
129+
return readNode(iterator);
128130
} finally {
129-
closer.close();
131+
if (parser != null) {
132+
parser.close();
133+
}
134+
if (iterator != null) {
135+
iterator.close();
136+
}
130137
}
131138
}
132139

src/main/java/com/github/fge/jackson/JsonNumEquals.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
package com.github.fge.jackson;
2121

2222
import com.fasterxml.jackson.databind.JsonNode;
23-
import com.google.common.base.Equivalence;
24-
import com.google.common.collect.Sets;
23+
import com.github.fge.jackson.com.google.common.base.Equivalence;
2524

25+
import java.util.HashSet;
2626
import java.util.Iterator;
2727
import java.util.Map;
2828
import java.util.Set;
2929

3030
/**
31-
* An {@link Equivalence} strategy for JSON Schema equality
31+
* An {@code com.google.common.base.Equivalence} like strategy for JSON Schema equality
3232
*
3333
* <p>{@link JsonNode} does a pretty good job of obeying the {@link
3434
* Object#equals(Object) equals()}/{@link Object#hashCode() hashCode()}
@@ -183,13 +183,32 @@ private boolean objectEquals(final JsonNode a, final JsonNode b)
183183
/*
184184
* Grab the key set from the first node
185185
*/
186-
final Set<String> keys = Sets.newHashSet(a.fieldNames());
186+
final Set<String> keys = new HashSet<>();
187+
Iterator<String> iterator1 = a.fieldNames();
188+
while (iterator1.hasNext()) {
189+
final String next = iterator1.next();
190+
if (next != null) {
191+
keys.add(next);
192+
} else {
193+
throw new NullPointerException();
194+
}
195+
}
187196

188197
/*
189198
* Grab the key set from the second node, and see if both sets are the
190199
* same. If not, objects are not equal, no need to check for children.
191200
*/
192-
final Set<String> set = Sets.newHashSet(b.fieldNames());
201+
final Set<String> set = new HashSet<>();
202+
Iterator<String> iterator2 = b.fieldNames();
203+
while (iterator2.hasNext()) {
204+
final String next = iterator2.next();
205+
if (next != null) {
206+
set.add(next);
207+
} else {
208+
throw new NullPointerException();
209+
}
210+
}
211+
193212
if (!set.equals(keys))
194213
return false;
195214

src/main/java/com/github/fge/jackson/NodeType.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import com.fasterxml.jackson.core.JsonToken;
2323
import com.fasterxml.jackson.databind.JsonNode;
2424
import com.fasterxml.jackson.databind.node.MissingNode;
25-
import com.google.common.base.Preconditions;
26-
import com.google.common.collect.ImmutableMap;
2725

26+
import java.util.Collections;
2827
import java.util.EnumMap;
28+
import java.util.HashMap;
2929
import java.util.Map;
3030

3131
/**
@@ -86,7 +86,7 @@ public enum NodeType
8686
* #getNodeType(JsonNode)})
8787
*/
8888
private static final Map<JsonToken, NodeType> TOKEN_MAP
89-
= new EnumMap<JsonToken, NodeType>(JsonToken.class);
89+
= new EnumMap<>(JsonToken.class);
9090

9191
static {
9292
TOKEN_MAP.put(JsonToken.START_ARRAY, ARRAY);
@@ -98,13 +98,13 @@ public enum NodeType
9898
TOKEN_MAP.put(JsonToken.START_OBJECT, OBJECT);
9999
TOKEN_MAP.put(JsonToken.VALUE_STRING, STRING);
100100

101-
final ImmutableMap.Builder<String, NodeType> builder
102-
= ImmutableMap.builder();
101+
final Map<String, NodeType> builder
102+
= new HashMap<>();
103103

104104
for (final NodeType type: NodeType.values())
105105
builder.put(type.name, type);
106106

107-
NAME_MAP = builder.build();
107+
NAME_MAP = Collections.unmodifiableMap(builder);
108108
}
109109

110110
NodeType(final String name)
@@ -140,8 +140,9 @@ public static NodeType getNodeType(final JsonNode node)
140140
{
141141
final JsonToken token = node.asToken();
142142
final NodeType ret = TOKEN_MAP.get(token);
143-
144-
Preconditions.checkNotNull(ret, "unhandled token type " + token);
143+
if (ret == null) {
144+
throw new NullPointerException("unhandled token type " + token);
145+
}
145146

146147
return ret;
147148
}

0 commit comments

Comments
 (0)