Skip to content

Commit 15387cb

Browse files
GH-2334 - Fix compiler and IDE warnings where appropriate.
Went through all the compiler and IDE warnings and fixed all compiler warnings and in the process setting the build to fail if any new one appears. Most of them are unchecked conversions, which we cannot avoid in all places. Those have been surpressed. This closes #2334.
1 parent 7f5bfb3 commit 15387cb

File tree

58 files changed

+837
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+837
-319
lines changed

pom.xml

+17
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,23 @@
720720
</execution>
721721
</executions>
722722
</plugin>
723+
<plugin>
724+
<groupId>org.apache.maven.plugins</groupId>
725+
<artifactId>maven-compiler-plugin</artifactId>
726+
<executions>
727+
<execution>
728+
<goals>
729+
<goal>compile</goal>
730+
</goals>
731+
<configuration combine.self="append">
732+
<compilerArgs>
733+
<arg>-Xlint:all,-options,-path</arg>
734+
<arg>-Werror</arg>
735+
</compilerArgs>
736+
</configuration>
737+
</execution>
738+
</executions>
739+
</plugin>
723740
</plugins>
724741

725742
</build>

src/main/java/org/springframework/data/neo4j/config/Neo4jCdiConfigurationSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ public Neo4jOperations neo4jOperations(
7272
}
7373

7474
@Produces @Singleton
75-
public Neo4jClient neo4jClient(Driver driver) {
75+
public Neo4jClient neo4jClient(@SuppressWarnings("CdiInjectionPointsInspection") Driver driver) {
7676
return Neo4jClient.create(driver);
7777
}
7878

7979
@Produces @Singleton
80-
public Neo4jMappingContext neo4jMappingContext(Driver driver, @Any Instance<Neo4jConversions> neo4JConversions) {
80+
public Neo4jMappingContext neo4jMappingContext(@SuppressWarnings("CdiInjectionPointsInspection") Driver driver, @Any Instance<Neo4jConversions> neo4JConversions) {
8181

8282
return new Neo4jMappingContext(resolve(neo4JConversions), driver.defaultTypeSystem());
8383
}
8484

8585
@Produces @Singleton
8686
public PlatformTransactionManager transactionManager(
87-
Driver driver, @Any Instance<DatabaseSelectionProvider> databaseNameProvider) {
87+
@SuppressWarnings("CdiInjectionPointsInspection") Driver driver, @Any Instance<DatabaseSelectionProvider> databaseNameProvider) {
8888

8989
return new Neo4jTransactionManager(driver, resolve(databaseNameProvider));
9090
}

src/main/java/org/springframework/data/neo4j/config/Neo4jCdiExtension.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.lang.annotation.Annotation;
1919
import java.util.Map;
20-
import java.util.Optional;
2120
import java.util.Set;
2221

2322
import javax.enterprise.event.Observes;
@@ -81,8 +80,7 @@ void addNeo4jBeansProducer(@Observes BeforeBeanDiscovery event) {
8180

8281
void registerRepositoryFactoryBeanPerRepositoryType(@Observes AfterBeanDiscovery event, BeanManager beanManager) {
8382

84-
Optional<CustomRepositoryImplementationDetector> optionalCustomRepositoryImplementationDetector =
85-
Optional.ofNullable(getCustomImplementationDetector());
83+
CustomRepositoryImplementationDetector optionalCustomRepositoryImplementationDetector = getCustomImplementationDetector();
8684

8785
for (Map.Entry<Class<?>, Set<Annotation>> entry : getRepositoryTypes()) {
8886

src/main/java/org/springframework/data/neo4j/config/Neo4jEntityScanner.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ private Neo4jEntityScanner(@Nullable ResourceLoader resourceLoader) {
7474
* @return a set of entity classes
7575
* @throws ClassNotFoundException if an entity class cannot be loaded
7676
*/
77-
@SafeVarargs
78-
public final Set<Class<?>> scan(String... basePackages) throws ClassNotFoundException {
77+
public Set<Class<?>> scan(String... basePackages) throws ClassNotFoundException {
7978
return scan(Arrays.stream(basePackages).collect(Collectors.toList()));
8079
}
8180

@@ -105,7 +104,10 @@ public Set<Class<?>> scan(Collection<String> packages) throws ClassNotFoundExcep
105104
for (String basePackage : packages) {
106105
if (StringUtils.hasText(basePackage)) {
107106
for (BeanDefinition candidate : scanner.findCandidateComponents(basePackage)) {
108-
entitySet.add(ClassUtils.forName(candidate.getBeanClassName(), classLoader));
107+
String beanClassName = candidate.getBeanClassName();
108+
if (beanClassName != null) {
109+
entitySet.add(ClassUtils.forName(beanClassName, classLoader));
110+
}
109111
}
110112
}
111113
}
@@ -120,7 +122,7 @@ public Set<Class<?>> scan(Collection<String> packages) throws ClassNotFoundExcep
120122
* @return a {@link ClassPathScanningCandidateComponentProvider} suitable to scan for Neo4j entities
121123
*/
122124
private static ClassPathScanningCandidateComponentProvider createClassPathScanningCandidateComponentProvider(
123-
ResourceLoader resourceLoader) {
125+
@Nullable ResourceLoader resourceLoader) {
124126

125127
ClassPathScanningCandidateComponentProvider delegate = new ClassPathScanningCandidateComponentProvider(false);
126128
if (resourceLoader != null) {

src/main/java/org/springframework/data/neo4j/core/DefaultNeo4jClient.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static class AutoCloseableQueryRunnerHandler implements InvocationHandler {
9999
this.target = target;
100100
}
101101

102+
@Nullable
102103
@Override
103104
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
104105

@@ -143,7 +144,7 @@ public DatabaseSelectionProvider getDatabaseSelectionProvider() {
143144
* Basically a holder of a cypher template supplier and a set of named parameters. It's main purpose is to orchestrate
144145
* the running of things with a bit of logging.
145146
*/
146-
class RunnableStatement {
147+
static class RunnableStatement {
147148

148149
RunnableStatement(Supplier<String> cypherSupplier) {
149150
this(cypherSupplier, new NamedParameters());
@@ -179,7 +180,7 @@ protected final Result runWith(AutoCloseableQueryRunner statementRunner) {
179180
*
180181
* @param ex the exception to translate
181182
* @param exceptionTranslator the {@link PersistenceExceptionTranslator} to be used for translation
182-
* @return
183+
* @return Any translated exception
183184
*/
184185
private static RuntimeException potentiallyConvertRuntimeException(RuntimeException ex,
185186
PersistenceExceptionTranslator exceptionTranslator) {
@@ -189,12 +190,12 @@ private static RuntimeException potentiallyConvertRuntimeException(RuntimeExcept
189190

190191
class DefaultRunnableSpec implements RunnableSpec {
191192

192-
private RunnableStatement runnableStatement;
193+
private final RunnableStatement runnableStatement;
193194

194195
private String targetDatabase;
195196

196197
DefaultRunnableSpec(Supplier<String> cypherSupplier) {
197-
this.targetDatabase = Neo4jClient.verifyDatabaseName(resolveTargetDatabaseName(targetDatabase));
198+
this.targetDatabase = Neo4jClient.verifyDatabaseName(resolveTargetDatabaseName(null));
198199
this.runnableStatement = new RunnableStatement(cypherSupplier);
199200
}
200201

@@ -230,8 +231,8 @@ public RunnableSpecTightToDatabase with(Function<T, Map<String, Object>> binder)
230231
}
231232

232233
@Override
233-
public OngoingBindSpec<?, RunnableSpecTightToDatabase> bind(@Nullable Object value) {
234-
return new DefaultOngoingBindSpec(value);
234+
public <T> OngoingBindSpec<T, RunnableSpecTightToDatabase> bind(T value) {
235+
return new DefaultOngoingBindSpec<>(value);
235236
}
236237

237238
@Override
@@ -243,8 +244,8 @@ public RunnableSpecTightToDatabase bindAll(Map<String, Object> newParameters) {
243244
@Override
244245
public <T> MappingSpec<T> fetchAs(Class<T> targetClass) {
245246

246-
return new DefaultRecordFetchSpec(this.targetDatabase, this.runnableStatement,
247-
new SingleValueMappingFunction(conversionService, targetClass));
247+
return new DefaultRecordFetchSpec<>(this.targetDatabase, this.runnableStatement,
248+
new SingleValueMappingFunction<>(conversionService, targetClass));
248249
}
249250

250251
@Override
@@ -368,7 +369,7 @@ class DefaultRunnableDelegation<T> implements RunnableDelegation<T>, OngoingDele
368369
}
369370

370371
@Override
371-
public RunnableDelegation in(@Nullable @SuppressWarnings("HiddenField") String targetDatabase) {
372+
public RunnableDelegation<T> in(@Nullable @SuppressWarnings("HiddenField") String targetDatabase) {
372373

373374
this.targetDatabase = Neo4jClient.verifyDatabaseName(targetDatabase);
374375
return this;

src/main/java/org/springframework/data/neo4j/core/DefaultReactiveNeo4jClient.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public RunnableSpecTightToDatabase with(Function<T, Map<String, Object>> binder)
154154
}
155155

156156
@Override
157-
public Neo4jClient.OngoingBindSpec<?, RunnableSpecTightToDatabase> bind(@Nullable Object value) {
158-
return new DefaultOngoingBindSpec(value);
157+
public <T> Neo4jClient.OngoingBindSpec<T, RunnableSpecTightToDatabase> bind(T value) {
158+
return new DefaultOngoingBindSpec<>(value);
159159
}
160160

161161
@Override
@@ -168,7 +168,7 @@ public RunnableSpecTightToDatabase bindAll(Map<String, Object> newParameters) {
168168
public <R> MappingSpec<R> fetchAs(Class<R> targetClass) {
169169

170170
return new DefaultRecordFetchSpec<>(this.targetDatabase, this.cypherSupplier, this.parameters,
171-
new SingleValueMappingFunction(conversionService, targetClass));
171+
new SingleValueMappingFunction<>(conversionService, targetClass));
172172
}
173173

174174
@Override
@@ -280,7 +280,7 @@ Mono<ResultSummary> run() {
280280
* exception if the conversation failed. Thus allows safe re-throwing of the return value.
281281
*
282282
* @param ex the exception to translate
283-
* @return
283+
* @return Any translated exception
284284
*/
285285
private RuntimeException potentiallyConvertRuntimeException(RuntimeException ex) {
286286
RuntimeException resolved = persistenceExceptionTranslator.translateExceptionIfPossible(ex);
@@ -303,7 +303,7 @@ class DefaultRunnableDelegation<T> implements RunnableDelegation<T>, OngoingDele
303303
}
304304

305305
@Override
306-
public RunnableDelegation in(@Nullable @SuppressWarnings("HiddenField") String targetDatabase) {
306+
public RunnableDelegation<T> in(@Nullable @SuppressWarnings("HiddenField") String targetDatabase) {
307307

308308
this.targetDatabase = Neo4jClient.verifyDatabaseName(targetDatabase);
309309
return this;
@@ -317,7 +317,7 @@ public Mono<T> run() {
317317
}
318318
}
319319

320-
final class RxStatementRunnerHolder {
320+
static final class RxStatementRunnerHolder {
321321
private final RxQueryRunner rxQueryRunner;
322322

323323
private final Publisher<Void> commit;

src/main/java/org/springframework/data/neo4j/core/NamedParameters.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.apiguardian.api.API;
2525
import org.neo4j.cypherdsl.core.Cypher;
26+
import org.springframework.lang.Nullable;
2627

2728
/**
2829
* @author Michael J. Simons
@@ -52,7 +53,7 @@ void addAll(Map<String, Object> newParameters) {
5253
* @param value The value of the new parameter
5354
* @throws IllegalStateException when a parameter with the given name already exists
5455
*/
55-
void add(String name, Object value) {
56+
void add(String name, @Nullable Object value) {
5657

5758
if (this.parameters.containsKey(name)) {
5859
Object previousValue = this.parameters.get(name);
@@ -80,7 +81,8 @@ public String toString() {
8081
.collect(Collectors.joining(", ", ":params {", "}"));
8182
}
8283

83-
private static Object formatValue(Object value) {
84+
@Nullable
85+
private static String formatValue(@Nullable Object value) {
8486
if (value == null) {
8587
return null;
8688
} else if (value instanceof String) {
@@ -90,7 +92,7 @@ private static Object formatValue(Object value) {
9092
.map(e -> String.format("%s: %s", e.getKey(), formatValue(e.getValue()))).collect(
9193
Collectors.joining(", ", "{", "}"));
9294
} else if (value instanceof Collection) {
93-
return ((Collection) value).stream().map(NamedParameters::formatValue).collect(
95+
return ((Collection<?>) value).stream().map(NamedParameters::formatValue).collect(
9496
Collectors.joining(", ", "[", "]"));
9597
}
9698

src/main/java/org/springframework/data/neo4j/core/Neo4jClient.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ interface RunnableDelegation<T> {
269269
* @return A possibly trimmed name of the database.
270270
* @throws IllegalArgumentException when the database name is not allowed with the underlying driver.
271271
*/
272-
static String verifyDatabaseName(String databaseName) {
272+
@Nullable
273+
static String verifyDatabaseName(@Nullable String databaseName) {
273274

274275
String newTargetDatabase = databaseName == null ? null : databaseName.trim();
275276
if (newTargetDatabase != null && newTargetDatabase.isEmpty()) {

src/main/java/org/springframework/data/neo4j/core/Neo4jOperations.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.data.neo4j.core.mapping.Neo4jPersistentProperty;
2626
import org.springframework.data.neo4j.repository.NoResultException;
2727
import org.springframework.data.neo4j.repository.query.QueryFragmentsAndParameters;
28+
import org.springframework.lang.Nullable;
2829

2930
/**
3031
* Specifies operations one can perform on a database, based on an <em>Domain Type</em>.
@@ -224,7 +225,7 @@ default <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
224225
*/
225226
<T> void deleteById(Object id, Class<T> domainType);
226227

227-
<T> void deleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersistentProperty versionProperty, Object versionValue);
228+
<T> void deleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersistentProperty versionProperty, @Nullable Object versionValue);
228229

229230
/**
230231
* Deletes all entities with one of the given ids, including all entities related to that entity.

0 commit comments

Comments
 (0)