Skip to content

Commit 71d94b3

Browse files
committed
Many warnings fixes.
* Removed unused headers, unused objects. * Fixed deprecated ObjectNode.put, .putAll to use .set, .setAll. * Added serialVersionUID as calculated by serialver to several exceptions. * Fixed a variety of ErrorProne findings: EqualsGetClass, ArrayAsKeyOfSetOrMap, MutableConstantField, VisibleForTestingMisused. * Suppressed some deprecated warnings on the tests for said deprecated features. * Suppressed an immutability warnings since Jackson databind doesn't include the immutable attribute on `JsonNode`.
1 parent 1c7682d commit 71d94b3

23 files changed

+38
-33
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ dependencies {
5959
compile(group: "com.github.fge", name: "uri-template", version: "0.9");
6060
// FIXME: no javadoc
6161
compile(group: "org.mozilla", name: "rhino", version: "1.7.7.1");
62-
compile(group: "com.google.code.findbugs", name: "jsr305", version: "3.0.2");
6362
testCompile(group: "org.testng", name: "testng", version: "6.10") {
6463
exclude(group: "junit", module: "junit");
6564
exclude(group: "org.beanshell", module: "bsh");

src/main/java/com/github/fge/jsonschema/SchemaVersion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public enum SchemaVersion
5454
;
5555

5656
private final URI location;
57+
@SuppressWarnings("ImmutableEnumChecker")
5758
private final JsonNode schema;
5859

5960
SchemaVersion(final String uri, final String resource)

src/main/java/com/github/fge/jsonschema/core/exceptions/InvalidSchemaException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
public final class InvalidSchemaException
2828
extends ProcessingException
2929
{
30+
private static final long serialVersionUID = 278790633227462029L;
31+
3032
public InvalidSchemaException(final ProcessingMessage message)
3133
{
3234
super(message);

src/main/java/com/github/fge/jsonschema/core/exceptions/JsonReferenceException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
public final class JsonReferenceException
3333
extends ProcessingException
3434
{
35+
private static final long serialVersionUID = 2630907528006411833L;
36+
3537
public JsonReferenceException(final ProcessingMessage message)
3638
{
3739
super(message);

src/main/java/com/github/fge/jsonschema/core/exceptions/ProcessingException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
public class ProcessingException
3636
extends Exception
3737
{
38+
private static final long serialVersionUID = -4194415456857460489L;
39+
3840
/**
3941
* The internal message
4042
*/

src/main/java/com/github/fge/jsonschema/core/keyword/syntax/checkers/SyntaxChecker.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
public interface SyntaxChecker
4848
{
4949
// FIXME: I should get rid of that -- it is used in only one place.
50-
@VisibleForTesting
5150
EnumSet<NodeType> getValidTypes();
5251

5352
/**

src/main/java/com/github/fge/jsonschema/core/keyword/syntax/checkers/hyperschema/LinksSyntaxChecker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import com.github.fge.jackson.NodeType;
2424
import com.github.fge.jackson.jsonpointer.JsonPointer;
2525
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
26-
import com.github.fge.jsonschema.core.report.ProcessingMessage;
27-
import com.github.fge.jsonschema.core.report.ProcessingReport;
2826
import com.github.fge.jsonschema.core.keyword.syntax.checkers.AbstractSyntaxChecker;
2927
import com.github.fge.jsonschema.core.keyword.syntax.checkers.SyntaxChecker;
28+
import com.github.fge.jsonschema.core.report.ProcessingMessage;
29+
import com.github.fge.jsonschema.core.report.ProcessingReport;
3030
import com.github.fge.jsonschema.core.tree.SchemaTree;
3131
import com.github.fge.msgsimple.bundle.MessageBundle;
3232
import com.github.fge.uritemplate.URITemplate;
@@ -46,7 +46,7 @@
4646
public final class LinksSyntaxChecker
4747
extends AbstractSyntaxChecker
4848
{
49-
private static final List<String> REQUIRED_LDO_PROPERTIES
49+
private static final ImmutableList<String> REQUIRED_LDO_PROPERTIES
5050
= ImmutableList.of("href", "rel");
5151

5252
private static final SyntaxChecker INSTANCE = new LinksSyntaxChecker();

src/main/java/com/github/fge/jsonschema/core/keyword/syntax/checkers/hyperschema/MediaSyntaxChecker.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@
2323
import com.github.fge.jackson.NodeType;
2424
import com.github.fge.jackson.jsonpointer.JsonPointer;
2525
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
26-
import com.github.fge.jsonschema.core.report.ProcessingReport;
2726
import com.github.fge.jsonschema.core.keyword.syntax.checkers.AbstractSyntaxChecker;
2827
import com.github.fge.jsonschema.core.keyword.syntax.checkers.SyntaxChecker;
28+
import com.github.fge.jsonschema.core.report.ProcessingReport;
2929
import com.github.fge.jsonschema.core.tree.SchemaTree;
3030
import com.github.fge.msgsimple.bundle.MessageBundle;
3131
import com.google.common.collect.ImmutableSet;
3232
import com.google.common.net.MediaType;
3333

3434
import java.util.Collection;
35-
import java.util.Set;
3635

3736
/**
3837
* Syntax checker for draft v4 hyperschema's {@code media} keyword
@@ -44,7 +43,7 @@ public final class MediaSyntaxChecker
4443
private static final String TYPE_FIELDNAME = "type";
4544

4645
// FIXME: INCOMPLETE: excludes "x-token" and "ietf-token"
47-
private static final Set<String> BINARY_ENCODINGS = ImmutableSet.of(
46+
private static final ImmutableSet<String> BINARY_ENCODINGS = ImmutableSet.of(
4847
"7bit", "8bit", "binary", "quoted-printable", "base64"
4948
);
5049

src/main/java/com/github/fge/jsonschema/core/report/AbstractProcessingReport.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
2323
import com.google.common.collect.ImmutableSet;
24-
import com.google.common.collect.Iterators;
2524
import com.google.common.collect.Lists;
2625

2726
import java.util.Iterator;

src/main/java/com/github/fge/jsonschema/core/report/ProcessingMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private ProcessingMessage putNull(final String key)
378378
public JsonNode asJson()
379379
{
380380
final ObjectNode ret = FACTORY.objectNode();
381-
ret.putAll(map);
381+
ret.setAll(map);
382382
return ret;
383383
}
384384

src/main/java/com/github/fge/jsonschema/core/tree/BaseSchemaTree.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.github.fge.jsonschema.core.exceptions.JsonReferenceException;
2929
import com.github.fge.jsonschema.core.ref.JsonRef;
3030
import com.github.fge.jsonschema.core.tree.key.SchemaKey;
31-
import com.google.common.base.Objects;
3231
import com.google.common.base.Preconditions;
3332

3433
import javax.annotation.Nonnull;
@@ -216,8 +215,8 @@ public final JsonNode asJson()
216215
{
217216
final ObjectNode ret = FACTORY.objectNode();
218217

219-
ret.put("loadingURI", FACTORY.textNode(key.getLoadingRef().toString()));
220-
ret.put("pointer", FACTORY.textNode(pointer.toString()));
218+
ret.set("loadingURI", FACTORY.textNode(key.getLoadingRef().toString()));
219+
ret.set("pointer", FACTORY.textNode(pointer.toString()));
221220

222221
return ret;
223222
}
@@ -248,7 +247,7 @@ public final boolean equals(@Nullable final Object obj)
248247
return false;
249248
if (this == obj)
250249
return true;
251-
if (getClass() != obj.getClass())
250+
if (!(obj instanceof BaseSchemaTree))
252251
return false;
253252
final BaseSchemaTree other = (BaseSchemaTree) obj;
254253
return key.equals(other.key) && pointer.equals(other.pointer);

src/main/java/com/github/fge/jsonschema/core/util/URIUtils.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@
1919

2020
package com.github.fge.jsonschema.core.util;
2121

22-
import com.github.fge.jsonschema.core.messages.JsonSchemaCoreMessageBundle;
2322
import com.github.fge.jsonschema.core.ref.JsonRef;
24-
import com.github.fge.msgsimple.bundle.MessageBundle;
25-
import com.github.fge.msgsimple.load.MessageBundles;
2623
import com.google.common.base.CharMatcher;
2724
import com.google.common.base.Function;
2825
import com.google.common.base.Optional;
2926

30-
import javax.annotation.Nullable;
3127
import java.net.URI;
3228
import java.net.URISyntaxException;
29+
import javax.annotation.Nullable;
3330

3431
/**
3532
* Utility class for URI normalization
@@ -52,9 +49,6 @@
5249
*/
5350
public final class URIUtils
5451
{
55-
private static final MessageBundle BUNDLE
56-
= MessageBundles.getBundle(JsonSchemaCoreMessageBundle.class);
57-
5852
/*
5953
* ASCII letters, and whatever is legal in a URI scheme
6054
*/

src/test/java/com/github/fge/jsonschema/core/exceptions/ProcessingExceptionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void innerExceptionClassAndMessageAreReported()
5858
.hasField("exceptionMessage", inner.getMessage());
5959
}
6060

61+
@SuppressWarnings("serial")
6162
private static class Foo
6263
extends Exception
6364
{

src/test/java/com/github/fge/jsonschema/core/keyword/syntax/SyntaxProcessorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void checkingWillNotDiveIntoUnknownKeywords()
195195
final ObjectNode node = FACTORY.objectNode();
196196
node.put(K1, K1);
197197
final ObjectNode schema = FACTORY.objectNode();
198-
schema.put("foo", node);
198+
schema.set("foo", node);
199199
final SchemaTree tree
200200
= new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema);
201201
final ValueHolder<SchemaTree> holder = ValueHolder.hold("schema", tree);
@@ -213,4 +213,4 @@ public void log(final LogLevel level, final ProcessingMessage message)
213213
{
214214
}
215215
}
216-
}
216+
}

src/test/java/com/github/fge/jsonschema/core/keyword/syntax/checkers/BasicSyntaxCheckerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void syntaxCheckingSucceedsOnValidTypes(final JsonNode node)
7171
final AbstractSyntaxChecker checker = spy(new DummyChecker());
7272
final ProcessingReport report = mock(ProcessingReport.class);
7373
final ObjectNode schema = FACTORY.objectNode();
74-
schema.put(KEYWORD, node);
74+
schema.set(KEYWORD, node);
7575
final SchemaTree tree
7676
= new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema);
7777

@@ -92,7 +92,7 @@ public void syntaxCheckingFailsOnInvalidTypes(final JsonNode node)
9292
{
9393
final NodeType type = NodeType.getNodeType(node);
9494
final ObjectNode schema = FACTORY.objectNode();
95-
schema.put(KEYWORD, node);
95+
schema.set(KEYWORD, node);
9696
final SchemaTree tree
9797
= new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema);
9898

src/test/java/com/github/fge/jsonschema/core/keyword/syntax/checkers/SyntaxCheckersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private static SchemaTree treeFromValue(final String keyword,
286286
final JsonNode node)
287287
{
288288
final ObjectNode schema = JacksonUtils.nodeFactory().objectNode();
289-
schema.put(keyword, node);
289+
schema.set(keyword, node);
290290
return new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema);
291291
}
292292

src/test/java/com/github/fge/jsonschema/core/load/SchemaLoaderTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.github.fge.jsonschema.core.load;
2121

22+
import static java.nio.charset.StandardCharsets.UTF_8;
23+
2224
import com.github.fge.jackson.JacksonUtils;
2325
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
2426
import com.github.fge.jsonschema.core.load.configuration.LoadingConfiguration;
@@ -48,7 +50,7 @@ public final class SchemaLoaderTest
4850
= MessageBundles.getBundle(JsonSchemaCoreMessageBundle.class);
4951

5052
private static final byte[] BYTES = JacksonUtils.nodeFactory().objectNode()
51-
.toString().getBytes();
53+
.toString().getBytes(UTF_8);
5254

5355
@Test
5456
public void namespacesAreRespected()

src/test/java/com/github/fge/jsonschema/core/load/URIManagerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.github.fge.jsonschema.core.load;
2121

22+
import static java.nio.charset.StandardCharsets.UTF_8;
23+
2224
import com.fasterxml.jackson.core.JsonParser;
2325
import com.fasterxml.jackson.databind.JsonNode;
2426
import com.github.fge.jackson.JsonNumEquals;
@@ -102,7 +104,7 @@ public void nonJSONInputShouldBeReportedAsSuch()
102104
{
103105
final URI uri = URI.create("foo://bar");
104106
final InputStream sampleStream
105-
= new ByteArrayInputStream("}".getBytes());
107+
= new ByteArrayInputStream("}".getBytes(UTF_8));
106108

107109
when(mock.fetch(any(URI.class))).thenReturn(sampleStream);
108110

src/test/java/com/github/fge/jsonschema/core/processing/CachingProcessorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public void exceptionIsThrownCorrectly()
139139
}
140140
}
141141

142+
@SuppressWarnings("serial")
142143
private static final class Foo
143144
extends ProcessingException
144145
{

src/test/java/com/github/fge/jsonschema/core/report/ProcessingMessageTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public void settingMessageAgainResetsArguments()
262262
assertEquals(message.getMessage(), "message2: bar");
263263
}
264264

265+
@SuppressWarnings("serial")
265266
private static final class Foo
266267
extends ProcessingException
267268
{

src/test/java/com/github/fge/jsonschema/core/tree/JsonTreeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void init()
4242
childObject.put("a", "b");
4343

4444
final ObjectNode rootNode = factory.objectNode();
45-
rootNode.put("object", childObject);
45+
rootNode.set("object", childObject);
4646
testNode = rootNode;
4747
}
4848

src/test/java/com/github/fge/jsonschema/core/tree/SchemaTreeTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Iterator<Object[]> getContexts()
112112
{
113113
final JsonNode node = data.get("lookups");
114114

115-
final Set<Object[]> set = Sets.newHashSet();
115+
final Set<Object[]> set = Sets.newIdentityHashSet();
116116

117117
for (final JsonNode element: node)
118118
set.add(new Object[] {
@@ -186,7 +186,7 @@ public void schemaWithoutDollarSchemaYieldsAnEmptyRef()
186186
public void nonTextualDollarSchemasYieldAnEmptyRef(final JsonNode node)
187187
{
188188
final ObjectNode testNode = FACTORY.objectNode();
189-
testNode.put("$schema", node);
189+
testNode.set("$schema", node);
190190

191191
final SchemaTree tree
192192
= new CanonicalSchemaTree(SchemaKey.anonymousKey(), testNode);
@@ -207,7 +207,7 @@ public Iterator<Object[]> nonLegalDollarSchemas()
207207
public void nonAbsoluteDollarSchemasYieldAnEmptyRef(final String s)
208208
{
209209
final ObjectNode testNode = FACTORY.objectNode();
210-
testNode.put("$schema", FACTORY.textNode(s));
210+
testNode.set("$schema", FACTORY.textNode(s));
211211

212212
final SchemaTree tree
213213
= new CanonicalSchemaTree(SchemaKey.anonymousKey(), testNode);
@@ -231,7 +231,7 @@ public void legalDollarSchemasAreReturnedCorrectly(final String s)
231231
{
232232
final JsonRef ref = JsonRef.fromString(s);
233233
final ObjectNode testNode = FACTORY.objectNode();
234-
testNode.put("$schema", FACTORY.textNode(s));
234+
testNode.set("$schema", FACTORY.textNode(s));
235235

236236
final SchemaTree tree
237237
= new CanonicalSchemaTree(SchemaKey.anonymousKey(), testNode);

src/test/java/com/github/fge/jsonschema/core/util/RegexECMA262HelperTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public Iterator<Object[]> ecma262regexes()
4545
invocationCount = 10,
4646
threadPoolSize = 4
4747
)
48+
@SuppressWarnings("deprecation")
4849
public void regexesAreCorrectlyAnalyzed(final String regex,
4950
final boolean valid)
5051
{
@@ -70,6 +71,7 @@ public Iterator<Object[]> regexTestCases()
7071
invocationCount = 10,
7172
threadPoolSize = 4
7273
)
74+
@SuppressWarnings("deprecation")
7375
public void regexMatchingIsDoneCorrectly(final String regex,
7476
final String input, final boolean valid)
7577
{

0 commit comments

Comments
 (0)