Skip to content

Commit 75d5252

Browse files
committed
MLE-23146 Addressed unchecked warnings in src/main/java
1 parent 5846bae commit 75d5252

29 files changed

+124
-49
lines changed

build.gradle

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,50 @@
44
// used for that. So we have to add the properties plugin to the buildscript classpath and then apply the properties
55
// plugin via subprojects below.
66
buildscript {
7-
repositories {
8-
maven {
9-
url = "https://plugins.gradle.org/m2/"
10-
}
11-
}
12-
dependencies {
13-
classpath "net.saliman:gradle-properties-plugin:1.5.2"
14-
}
7+
repositories {
8+
maven {
9+
url = "https://plugins.gradle.org/m2/"
10+
}
11+
}
12+
dependencies {
13+
classpath "net.saliman:gradle-properties-plugin:1.5.2"
14+
}
1515
}
1616

1717
subprojects {
18-
apply plugin: "net.saliman.properties"
19-
apply plugin: 'java'
18+
apply plugin: "net.saliman.properties"
19+
apply plugin: 'java'
2020

21-
tasks.withType(JavaCompile) {
22-
options.encoding = 'UTF-8'
23-
}
21+
tasks.withType(JavaCompile) {
22+
options.encoding = 'UTF-8'
23+
options.compilerArgs += ["-Xlint:unchecked"]
24+
}
2425

25-
// To ensure that the Java Client continues to support Java 8, both source and target compatibility are set to 1.8.
26-
java {
27-
sourceCompatibility = 1.8
28-
targetCompatibility = 1.8
29-
}
26+
// To ensure that the Java Client continues to support Java 8, both source and target compatibility are set to 1.8.
27+
java {
28+
sourceCompatibility = 1.8
29+
targetCompatibility = 1.8
30+
}
3031

31-
configurations {
32-
testImplementation.extendsFrom compileOnly
33-
}
32+
configurations {
33+
testImplementation.extendsFrom compileOnly
34+
}
3435

35-
repositories {
36-
mavenLocal()
37-
mavenCentral()
38-
}
36+
repositories {
37+
mavenLocal()
38+
mavenCentral()
39+
}
3940

4041
test {
4142
systemProperty "file.encoding", "UTF-8"
4243
systemProperty "javax.xml.stream.XMLOutputFactory", "com.sun.xml.internal.stream.XMLOutputFactoryImpl"
4344
}
4445

4546
// Until we do a cleanup of javadoc errors, the build (and specifically the javadoc task) fails on Java 11
46-
// and higher. Preventing that until the cleanup can occur.
47-
javadoc.failOnError = false
47+
// and higher. Preventing that until the cleanup can occur.
48+
javadoc.failOnError = false
4849

49-
// Ignores warnings on param tags with no descriptions. Will remove this once javadoc errors are addressed.
50-
// Until then, it's just a lot of noise.
51-
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
50+
// Ignores warnings on param tags with no descriptions. Will remove this once javadoc errors are addressed.
51+
// Until then, it's just a lot of noise.
52+
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
5253
}

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/HostAvailabilityListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ public HostAvailabilityListener withMinHosts(int numHosts) {
141141
*
142142
* @return this instance (for method chaining)
143143
*/
144-
public HostAvailabilityListener withHostUnavailableExceptions(Class<Throwable>... exceptionTypes) {
144+
@SafeVarargs
145+
public final HostAvailabilityListener withHostUnavailableExceptions(Class<Throwable>... exceptionTypes) {
145146
hostUnavailableExceptions = new ArrayList<>();
146147
for ( Class<Throwable> exception : exceptionTypes ) {
147148
hostUnavailableExceptions.add(exception);

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/JSONSplitter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,15 @@ public Stream<T> split(JsonParser input) throws IOException {
154154
* files.The splitFilename could either be provided here or in user-defined UriMaker.
155155
* @return a stream of DocumentWriteOperation to write to database
156156
*/
157+
@SuppressWarnings("unchecked")
157158
public Stream<DocumentWriteOperation> splitWriteOperations(JsonParser input, String splitFilename) {
158159
if (input == null) {
159160
throw new IllegalArgumentException("Input cannot be null");
160161
}
161162
count = 0;
162163

163164
this.splitFilename = splitFilename;
164-
JSONSplitter.DocumentWriteOperationSpliterator spliterator =
165+
JSONSplitter.DocumentWriteOperationSpliterator<T> spliterator =
165166
new JSONSplitter.DocumentWriteOperationSpliterator<>(this, input);
166167
return StreamSupport.stream(spliterator, true);
167168
}

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/PathSplitter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public Stream<DocumentWriteOperation> splitDocumentWriteOperations(Stream<Path>
104104
return paths.flatMap(this::flatMapDocumentWriteOperations);
105105
}
106106

107+
@SuppressWarnings("unchecked")
107108
private Stream<? extends AbstractWriteHandle> flatMapHandles(Path path) {
108109
String extension = getExtension(path);
109110
Splitter splitter = lookupSplitter(extension);
@@ -119,6 +120,7 @@ private Stream<? extends AbstractWriteHandle> flatMapHandles(Path path) {
119120
}
120121
}
121122

123+
@SuppressWarnings("unchecked")
122124
private Stream<DocumentWriteOperation> flatMapDocumentWriteOperations(Path path) {
123125
String extension = getExtension(path);
124126
Splitter splitter = lookupSplitter(extension);
@@ -153,6 +155,7 @@ private String getExtension(Path path) {
153155
return matcher.group(1);
154156
}
155157

158+
@SuppressWarnings("unchecked")
156159
private Splitter<? extends AbstractWriteHandle> lookupSplitter(String extension) {
157160
Splitter splitter = splitterMap.get(extension);
158161
if (splitter == null && splitterMap.get(DEFAULT_SPLITTER_KEY) != null) {

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/ProgressListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public ProgressListener() {
5555
* Use this constructor for when the total number of results isn't known ahead of time.
5656
* @param consumers one or more callbacks for progress updates
5757
*/
58+
@SafeVarargs
5859
public ProgressListener(Consumer<ProgressUpdate>... consumers) {
5960
this(0, consumers);
6061
}
@@ -65,6 +66,7 @@ public ProgressListener(Consumer<ProgressUpdate>... consumers) {
6566
* @param totalResults the total number of results that is the processing goal
6667
* @param consumers one or more callbacks for progress updates
6768
*/
69+
@SafeVarargs
6870
public ProgressListener(long totalResults, Consumer<ProgressUpdate>... consumers) {
6971
this.totalResults = totalResults;
7072
for (Consumer<ProgressUpdate> consumer : consumers) {

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/RowBatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ public interface RowBatcher<T> extends Batcher {
218218
* rows when more than one callback function is needed.
219219
* @param listeners the success listeners
220220
*/
221-
void setSuccessListeners(RowBatchSuccessListener<T>... listeners);
221+
@SuppressWarnings("unchecked")
222+
void setSuccessListeners(RowBatchSuccessListener<T>... listeners);
222223
/**
223224
* Specifies the callback functions for errors when more than
224225
* one callback function is needed.

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/XMLSplitter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ private static class DocumentWriteOperationSpliterator<T extends XMLWriteHandle>
483483
super(xmlSplitter, input);
484484
}
485485
@Override
486+
@SuppressWarnings("unchecked")
486487
public boolean tryAdvance(Consumer<? super DocumentWriteOperation> action) {
487488

488489
T handle = (T) getNextHandle();

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/BatchImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public BatchImpl(Class<T> as) {
2424
}
2525

2626
@Override
27+
@SuppressWarnings("unchecked")
2728
public T[] getItems() {
2829
if (items == null) {
2930
return (T[]) Array.newInstance(as, 0);
@@ -35,15 +36,22 @@ public BatchImpl<T> withItems(T[] items) {
3536
return this;
3637
}
3738

39+
@SuppressWarnings("unchecked")
3840
public BatchImpl<T> withClient(DatabaseClient client) {
3941
return (BatchImpl<T>) super.withClient(client);
4042
}
43+
44+
@SuppressWarnings("unchecked")
4145
public BatchImpl<T> withTimestamp(Calendar timestamp) {
4246
return (BatchImpl<T>) super.withTimestamp(timestamp);
4347
}
48+
49+
@SuppressWarnings("unchecked")
4450
public BatchImpl<T> withJobTicket(JobTicket jobTicket) {
4551
return (BatchImpl<T>) super.withJobTicket(jobTicket);
4652
}
53+
54+
@SuppressWarnings("unchecked")
4755
public BatchImpl<T> withJobBatchNumber(long jobBatchNumber) {
4856
return (BatchImpl<T>) super.withJobBatchNumber(jobBatchNumber);
4957
}

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/RowBatcherImpl.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RowBatcherImpl<T> extends BatcherImpl implements RowBatcher<T> {
4444
private final AtomicLong failedBatches = new AtomicLong(0);
4545
private final AtomicInteger runningThreads = new AtomicInteger(0);
4646
private RowBatchFailureListener[] failureListeners;
47-
private RowBatchSuccessListener[] successListeners;
47+
private RowBatchSuccessListener<T>[] successListeners;
4848

4949
private RawPlanDefinition pagedPlan;
5050
private long rowCount = 0;
@@ -162,6 +162,7 @@ public RowBatcher<T> withThreadCount(int threadCount) {
162162
}
163163

164164
@Override
165+
@SuppressWarnings("unchecked")
165166
public RowBatcher<T> onSuccess(RowBatchSuccessListener listener) {
166167
requireNotStarted("Must set success listener before starting job");
167168
if (listener == null) {
@@ -212,30 +213,38 @@ public RowBatcher<T> withConsistentSnapshot() {
212213
}
213214

214215
@Override
215-
public RowBatchSuccessListener[] getSuccessListeners() {
216+
@SuppressWarnings("unchecked")
217+
public RowBatchSuccessListener<T>[] getSuccessListeners() {
216218
return successListeners;
217219
}
220+
218221
@Override
219222
public RowBatchFailureListener[] getFailureListeners() {
220223
return failureListeners;
221224
}
225+
226+
@SafeVarargs
222227
@Override
223-
public void setSuccessListeners(RowBatchSuccessListener... listeners) {
228+
public final void setSuccessListeners(RowBatchSuccessListener<T>... listeners) {
224229
requireNotStarted("Must set success listeners before starting job");
225230
this.successListeners = listeners;
226231
}
232+
233+
@SafeVarargs
227234
@Override
228-
public void setFailureListeners(RowBatchFailureListener... listeners) {
235+
public final void setFailureListeners(RowBatchFailureListener... listeners) {
229236
requireNotStarted("Must set failure listeners before starting job");
230237
this.failureListeners = listeners;
231238
}
232239
private void initRequestEvent(RowBatchEventImpl event) {
233240
event.withClient(getPrimaryClient());
234241
event.withJobTicket(getJobTicket());
235242
}
243+
244+
@SuppressWarnings("unchecked")
236245
private void notifySuccess(RowBatchSuccessListener.RowBatchResponseEvent<T> event) {
237246
if (successListeners == null || successListeners.length == 0) return;
238-
for (RowBatchSuccessListener successListener: successListeners) {
247+
for (RowBatchSuccessListener<T> successListener: successListeners) {
239248
try {
240249
successListener.processEvent(event);
241250
} catch(Throwable e) {
@@ -413,6 +422,7 @@ public synchronized void start(JobTicket ticket) {
413422
}
414423
}
415424

425+
@SuppressWarnings("unchecked")
416426
private boolean readRows(RowBatchCallable<T> callable) {
417427
// assumes a batch size of at least 2 to avoid unsigned overflow
418428
long currentBatch = this.batchNum.incrementAndGet();
@@ -538,9 +548,12 @@ public synchronized RowBatcher<T> withForestConfig(ForestConfiguration forestCon
538548
return this;
539549
}
540550

551+
@SuppressWarnings("unchecked")
541552
private void submit(Callable<Boolean> callable) {
542553
submit(new FutureTask(callable));
543554
}
555+
556+
@SuppressWarnings("unchecked")
544557
private void submit(FutureTask<Boolean> task) {
545558
threadPool.execute(task);
546559
}
@@ -552,10 +565,14 @@ static private class RowBatchCallable<T> implements Callable<Boolean> {
552565
this.rowBatcher = rowBatcher;
553566
this.handle = handle;
554567
}
568+
569+
@SuppressWarnings("unchecked")
555570
private ContentHandle<T> getHandle() {
556571
return handle;
557572
}
573+
558574
@Override
575+
@SuppressWarnings("unchecked")
559576
public Boolean call() {
560577
try {
561578
return rowBatcher.readRows(this);

marklogic-client-api/src/main/java/com/marklogic/client/dataservices/InputCaller.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface InputCaller<I> extends IOEndpoint {
2525
* @param <I> the input content representation (such as String)
2626
* @return the InputCaller instance for calling the endpoint.
2727
*/
28+
@SuppressWarnings("unchecked")
2829
static <I> InputCaller<I> on(DatabaseClient client, JSONWriteHandle apiDecl, BufferableContentHandle<I,?> inputHandle) {
2930
return new InputEndpointImpl(client, apiDecl, new HandleProvider.ContentHandleProvider<>(inputHandle,null));
3031
}
@@ -40,6 +41,7 @@ static <I> InputCaller<I> on(DatabaseClient client, JSONWriteHandle apiDecl, Buf
4041
* @param <I> the input handle
4142
* @return the InputOutputCaller instance for calling the endpoint.
4243
*/
44+
@SuppressWarnings("unchecked")
4345
static <IC,IR,I extends BufferableContentHandle<IC,IR>> InputCaller<I> onHandles(
4446
DatabaseClient client, JSONWriteHandle apiDecl, I inputHandle
4547
) {

0 commit comments

Comments
 (0)