From baaae83b6cb7272fdb5effb1e9c46d8677af062a Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Sat, 18 Nov 2023 14:06:56 +0100 Subject: [PATCH] change severity of some error prone check from warn to error --- core/pom.xml | 5 ++++ .../validation/MultipleOfKeywordType.java | 1 + .../validation/UniqueItemsKeywordType.java | 5 ++-- .../JsonTestSuiteTestCaseProvider.java | 1 + .../jsonschema/core/testsuite/Resources.java | 2 ++ core/src/test/java/module-info.java | 1 + pom.xml | 21 +++++++++++++++- testsuite-junit-platform-engine/pom.xml | 4 +++ .../engine/JsonSchemaTestSuiteEngine.java | 11 ++++---- .../testsuite/junit/engine/Resources.java | 2 ++ .../src/main/java/module-info.java | 1 + .../testsuite/junit/engine/ResourceTest.java | 25 +++++++++++-------- .../testsuite/junit/engine/ResourcesTest.java | 20 ++++++++------- 13 files changed, 71 insertions(+), 28 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 64a141e4..e6d27979 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -50,6 +50,11 @@ hamcrest-optional test + + com.google.errorprone + error_prone_annotations + test + jakarta.json diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java index aa9fa431..6d3ff4d6 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java @@ -63,6 +63,7 @@ public boolean hasName(final String name) { } @Override + @SuppressWarnings("BigDecimalEquals") public boolean isValidFor(final JsonValue instance) { return ( !InstanceType.NUMBER.isInstance(instance) || diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java index c2747423..892ca6d3 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java @@ -119,11 +119,12 @@ public int hashCode() { @Override public boolean equals(final Object obj) { return ( - this == obj || (obj != null && getClass() == obj.getClass() && equals((JsonValueNumberEqualsFix) obj)) + this == obj || (obj != null && getClass() == obj.getClass() && isEquals((JsonValueNumberEqualsFix) obj)) ); } - private boolean equals(final JsonValueNumberEqualsFix other) { + @SuppressWarnings("BigDecimalEquals") + private boolean isEquals(final JsonValueNumberEqualsFix other) { final boolean result; if (isNumber() && other.isNumber()) { result = normalizeValue().equals(other.normalizeValue()); diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java index 2ea4fb8a..a12a7709 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java @@ -37,6 +37,7 @@ class JsonTestSuiteTestCaseProvider implements ArgumentsProvider { @Override + @SuppressWarnings("MustBeClosedChecker") public Stream provideArguments(final ExtensionContext context) throws Exception { return new Resources() .all() diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java index 26f785d8..9c7c2c3c 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java @@ -48,6 +48,7 @@ public Resources(final String baseDir) { this.baseDir = baseDir; } + @com.google.errorprone.annotations.MustBeClosed Stream all() { try { return StreamSupport @@ -83,6 +84,7 @@ public PathResources(final Path path) { this.path = Objects.requireNonNull(path); } + @SuppressWarnings("StreamResourceLeak") Stream toResources() { final Stream result; try { diff --git a/core/src/test/java/module-info.java b/core/src/test/java/module-info.java index b7ce75fd..2950fd11 100644 --- a/core/src/test/java/module-info.java +++ b/core/src/test/java/module-info.java @@ -26,6 +26,7 @@ requires io.github.sebastiantoepfer.jsonschema.vocabulary.spi; requires jakarta.json; + requires com.google.errorprone.annotations; requires org.junit.jupiter.api; requires org.junit.jupiter.params; requires org.junit.jupiter.engine; diff --git a/pom.xml b/pom.xml index 85476c59..53864323 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,11 @@ spotbugs-annotations 4.8.1 + + com.google.errorprone + error_prone_annotations + 2.23.0 + org.junit @@ -121,7 +126,21 @@ -XDcompilePolicy=simple - -Xplugin:ErrorProne + + -Xplugin:ErrorProne \ + -XepExcludedPaths:.*/target/generated-sources/.* \ + -Xep:EqualsGetClass:OFF \ + -Xep:MissingOverride:ERROR \ + -Xep:DefaultCharset:ERROR \ + -Xep:BadImport:ERROR \ + -Xep:TypeParameterShadowing:ERROR \ + -Xep:NonCanonicalType:ERROR \ + -Xep:EqualsIncompatibleType:ERROR \ + -Xep:BigDecimalEquals:ERROR \ + -Xep:UndefinedEquals:ERROR \ + -Xep:StreamResourceLeak:ERROR \ + -Xep:NonOverridingEquals:ERROR + diff --git a/testsuite-junit-platform-engine/pom.xml b/testsuite-junit-platform-engine/pom.xml index 8bdd3673..c8de0c64 100644 --- a/testsuite-junit-platform-engine/pom.xml +++ b/testsuite-junit-platform-engine/pom.xml @@ -27,6 +27,10 @@ com.github.spotbugs spotbugs-annotations + + com.google.errorprone + error_prone_annotations + org.junit.jupiter diff --git a/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/JsonSchemaTestSuiteEngine.java b/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/JsonSchemaTestSuiteEngine.java index a8cec808..d14e28fe 100644 --- a/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/JsonSchemaTestSuiteEngine.java +++ b/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/JsonSchemaTestSuiteEngine.java @@ -41,11 +41,12 @@ public String getId() { @Override public TestDescriptor discover(final EngineDiscoveryRequest discoveryRequest, final UniqueId uniqueId) { final TestDescriptor result = new EngineDescriptor(uniqueId, "Json Schema Test"); - new Resources() - .all() - .filter(resource -> resource.hasExtension("json")) - .map(JsonSchemaSuitesTestDescriptor::new) - .forEach(result::addChild); + try (final Stream res = new Resources().all()) { + res + .filter(resource -> resource.hasExtension("json")) + .map(JsonSchemaSuitesTestDescriptor::new) + .forEach(result::addChild); + } return result; } diff --git a/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/Resources.java b/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/Resources.java index 4fa18af1..f98fd551 100644 --- a/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/Resources.java +++ b/testsuite-junit-platform-engine/src/main/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/Resources.java @@ -48,6 +48,7 @@ public Resources(final String baseDir) { this.baseDir = baseDir; } + @com.google.errorprone.annotations.MustBeClosed Stream all() { try { return StreamSupport @@ -83,6 +84,7 @@ public PathResources(final Path path) { this.path = Objects.requireNonNull(path); } + @SuppressWarnings("StreamResourceLeak") Stream toResources() { final Stream result; try { diff --git a/testsuite-junit-platform-engine/src/main/java/module-info.java b/testsuite-junit-platform-engine/src/main/java/module-info.java index 84e5715a..c7ad8af1 100644 --- a/testsuite-junit-platform-engine/src/main/java/module-info.java +++ b/testsuite-junit-platform-engine/src/main/java/module-info.java @@ -31,5 +31,6 @@ requires org.junit.platform.engine; requires org.junit.platform.commons; requires com.github.spotbugs.annotations; + requires com.google.errorprone.annotations; requires jakarta.json; } diff --git a/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourceTest.java b/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourceTest.java index 0fe880d8..e4d2fc4a 100644 --- a/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourceTest.java +++ b/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourceTest.java @@ -26,7 +26,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import io.github.sebastiantoepfer.jsonschema.testsuite.junit.engine.Resource; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -45,16 +46,18 @@ void should_determine_name() { @Test void should_return_content() throws Exception { - assertThat( - new String(new Resource("tests/test_resource.json").content().readAllBytes()), - is( - """ - { - "name": "sebastian" - } - """ - ) - ); + try (final InputStream content = new Resource("tests/test_resource.json").content()) { + assertThat( + new String(content.readAllBytes(), StandardCharsets.UTF_8), + is( + """ + { + "name": "sebastian" + } + """ + ) + ); + } } @Test diff --git a/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourcesTest.java b/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourcesTest.java index 3c5aa2d6..352c1990 100644 --- a/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourcesTest.java +++ b/testsuite-junit-platform-engine/src/test/java/io/github/sebastiantoepfer/jsonschema/testsuite/junit/engine/ResourcesTest.java @@ -26,28 +26,30 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItems; -import io.github.sebastiantoepfer.jsonschema.testsuite.junit.engine.Resource; -import io.github.sebastiantoepfer.jsonschema.testsuite.junit.engine.Resources; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; class ResourcesTest { @Test void should_find_resources_from_classpath() { - assertThat(new Resources().all().toList(), hasItems(new Resource("tests/test_resource.json"))); + try (final Stream res = new Resources().all()) { + assertThat(res.toList(), hasItems(new Resource("tests/test_resource.json"))); + } } @Test void should_find_resources_in_subdir_from_classpath() { - assertThat(new Resources("tests").all().toList(), hasItems(new Resource("tests/test_resource.json"))); + try (final Stream res = new Resources("tests").all()) { + assertThat(res.toList(), hasItems(new Resource("tests/test_resource.json"))); + } } @Test void should_find_resources_in_metainf() { - //to kill all mutants, we need a resource from non-test classpath - assertThat( - new Resources("META-INF").all().toList(), - hasItems(new Resource("META-INF/services/org.junit.platform.engine.TestEngine")) - ); + try (final Stream res = new Resources("META-INF").all()) { + //to kill all mutants, we need a resource from non-test classpath + assertThat(res.toList(), hasItems(new Resource("META-INF/services/org.junit.platform.engine.TestEngine"))); + } } }