Skip to content

Commit b295c62

Browse files
committed
Using NotNull only for method params
1 parent 1bb1203 commit b295c62

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

marklogic-spark-api/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ dependencies {
1111
exclude group: "com.fasterxml.jackson.dataformat"
1212
}
1313

14-
// This is compileOnly as Spark will provide its own copy.
14+
// This is compileOnly as Spark will provide its own copy at runtime.
1515
compileOnly "com.fasterxml.jackson.core:jackson-databind:2.15.2"
1616

17+
// Used for null-checks; Spark should provide its own copy at runtime as well, but this is included just in case
18+
// a particular Spark runtime doesn't include this.
19+
implementation "jakarta.validation:jakarta.validation-api:2.0.2"
20+
1721
// For logging.
1822
implementation "org.slf4j:jcl-over-slf4j:2.0.13"
1923

marklogic-spark-api/src/main/java/com/marklogic/spark/core/classifier/TextClassifierFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import com.smartlogic.cloud.TokenFetcher;
1515
import org.w3c.dom.Document;
1616

17+
import javax.validation.constraints.NotNull;
1718
import java.net.MalformedURLException;
1819
import java.net.URL;
1920
import java.util.HashMap;
2021
import java.util.Map;
21-
import java.util.Objects;
2222

2323
public abstract class TextClassifierFactory {
2424

@@ -141,8 +141,7 @@ public static class MockSemaphoreProxy implements SemaphoreProxy {
141141

142142
// Sonar doesn't like this static assignment, but it's fine in a class that's only used as a mock.
143143
@SuppressWarnings("java:S3010")
144-
private MockSemaphoreProxy(String mockResponse) {
145-
Objects.requireNonNull(mockResponse);
144+
private MockSemaphoreProxy(@NotNull String mockResponse) {
146145
this.mockResponse = new DOMHelper(null).parseXmlString(mockResponse, null);
147146
timesInvoked = 0;
148147
}

marklogic-spark-connector/src/main/java/com/marklogic/spark/reader/document/OpticTriplesReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.slf4j.Logger;
2121
import org.slf4j.LoggerFactory;
2222

23+
import javax.validation.constraints.NotNull;
2324
import java.io.IOException;
2425
import java.net.URI;
2526
import java.net.URISyntaxException;
@@ -105,8 +106,7 @@ public void close() {
105106
IOUtils.closeQuietly(this.currentRowSet);
106107
}
107108

108-
private void readNextBatchOfTriples(List<String> uris) {
109-
Objects.requireNonNull(uris);
109+
private void readNextBatchOfTriples(@NotNull List<String> uris) {
110110
PlanBuilder.ModifyPlan plan = op
111111
.fromTriples(op.pattern(op.col("subject"), op.col("predicate"), op.col(OBJECT_COLUMN), op.graphCol(GRAPH_COLUMN)))
112112
.where(op.cts.documentQuery(op.xs.stringSeq(uris.toArray(new String[0]))));

marklogic-spark-connector/src/main/java/com/marklogic/spark/reader/file/RdfZipFileReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import org.apache.commons.io.IOUtils;
99
import org.apache.spark.sql.catalyst.InternalRow;
1010
import org.apache.spark.sql.connector.read.PartitionReader;
11-
import org.jetbrains.annotations.NotNull;
1211
import org.slf4j.Logger;
1312
import org.slf4j.LoggerFactory;
1413

14+
import javax.validation.constraints.NotNull;
1515
import java.io.IOException;
1616
import java.io.InputStream;
1717
import java.util.zip.ZipEntry;

marklogic-spark-connector/src/main/java/com/marklogic/spark/writer/file/ContentWriter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ void writeContent(InternalRow row, @NotNull OutputStream outputStream) throws IO
7272
streamDocumentToFile(row, outputStream);
7373
} else if (this.prettyPrint) {
7474
prettyPrintContent(row, outputStream);
75-
} else if (this.encoding != null) {
76-
// We know the string from MarkLogic is UTF-8, so we use getBytes to convert it to the user's
77-
// specified encoding (as opposed to new String(bytes, encoding)).
75+
} else {
7876
byte[] binary = row.getBinary(1);
7977
Objects.requireNonNull(binary);
80-
outputStream.write(new String(binary).getBytes(this.encoding));
81-
} else {
82-
outputStream.write(row.getBinary(1));
78+
if (this.encoding != null) {
79+
// We know the string from MarkLogic is UTF-8, so we use getBytes to convert it to the user's
80+
// specified encoding (as opposed to new String(bytes, encoding)).
81+
outputStream.write(new String(binary).getBytes(this.encoding));
82+
} else {
83+
outputStream.write(binary);
84+
}
8385
}
8486
}
8587

tests/src/test/java/com/marklogic/spark/writer/file/WriteDocumentZipFilesTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.spark.sql.Dataset;
1313
import org.apache.spark.sql.Row;
1414
import org.apache.spark.sql.SaveMode;
15-
import org.jetbrains.annotations.NotNull;
1615
import org.junit.jupiter.api.Test;
1716
import org.junit.jupiter.api.io.TempDir;
1817

@@ -46,7 +45,7 @@ void defaultPartitionCount(@TempDir Path tempDir) throws Exception {
4645
}
4746

4847
@Test
49-
void customPartitionCount(@TempDir @NotNull Path tempDir) throws IOException {
48+
void customPartitionCount(@TempDir Path tempDir) throws IOException {
5049
readAuthorCollection()
5150
.repartition(5)
5251
.write()
@@ -64,7 +63,7 @@ void customPartitionCount(@TempDir @NotNull Path tempDir) throws IOException {
6463
}
6564

6665
@Test
67-
void opaqueURI(@TempDir @NotNull Path tempDir) throws IOException {
66+
void opaqueURI(@TempDir Path tempDir) throws IOException {
6867
final String uri = "org:example/123.xml";
6968

7069
getDatabaseClient().newXMLDocumentManager().write(uri,

0 commit comments

Comments
 (0)