Skip to content

Commit e6c9796

Browse files
committed
Nullability fine-tuning based on IntelliJ IDEA 2018.3 inspection
Issue: SPR-15540 (cherry picked from commit bf272b0)
1 parent 23d1049 commit e6c9796

File tree

12 files changed

+87
-85
lines changed

12 files changed

+87
-85
lines changed

spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ public void setWriteMethod(@Nullable Method writeMethod) {
314314
}
315315

316316
@Override
317+
@Nullable
317318
public Class<?> getPropertyType() {
318319
if (this.propertyType == null) {
319320
try {
@@ -425,6 +426,7 @@ public void setWriteMethod(@Nullable Method writeMethod) {
425426
}
426427

427428
@Override
429+
@Nullable
428430
public Class<?> getPropertyType() {
429431
if (this.propertyType == null) {
430432
try {
@@ -460,6 +462,7 @@ public void setIndexedWriteMethod(@Nullable Method indexedWriteMethod) throws In
460462
}
461463

462464
@Override
465+
@Nullable
463466
public Class<?> getIndexedPropertyType() {
464467
if (this.indexedPropertyType == null) {
465468
try {

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ private Object resolveBeanReference(Method beanMethod, Object[] beanMethodArgs,
395395
Object beanInstance = (useArgs ? beanFactory.getBean(beanName, beanMethodArgs) :
396396
beanFactory.getBean(beanName));
397397
if (!ClassUtils.isAssignableValue(beanMethod.getReturnType(), beanInstance)) {
398+
// Detect package-protected NullBean instance through equals(null) check
398399
if (beanInstance.equals(null)) {
399400
if (logger.isDebugEnabled()) {
400401
logger.debug(String.format("@Bean method %s.%s called as bean reference " +

spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -170,11 +170,12 @@ public void afterPropertiesSet() throws JMException, IOException {
170170
try {
171171
if (this.threaded) {
172172
// Start the connector server asynchronously (in a separate thread).
173+
final JMXConnectorServer serverToStart = this.connectorServer;
173174
Thread connectorThread = new Thread() {
174175
@Override
175176
public void run() {
176177
try {
177-
connectorServer.start();
178+
serverToStart.start();
178179
}
179180
catch (IOException ex) {
180181
throw new JmxException("Could not start JMX connector server after delay", ex);

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,25 @@ public static ParsedSql parseSqlStatement(final String sql) {
111111
char c = statement[i];
112112
if (c == ':' || c == '&') {
113113
int j = i + 1;
114-
if (j < statement.length && statement[j] == ':' && c == ':') {
114+
if (c == ':' && j < statement.length && statement[j] == ':') {
115115
// Postgres-style "::" casting operator should be skipped
116116
i = i + 2;
117117
continue;
118118
}
119119
String parameter = null;
120-
if (j < statement.length && c == ':' && statement[j] == '{') {
120+
if (c == ':' && j < statement.length && statement[j] == '{') {
121121
// :{x} style parameter
122-
while (j < statement.length && statement[j] != '}') {
122+
while (statement[j] != '}') {
123123
j++;
124+
if (j >= statement.length) {
125+
throw new InvalidDataAccessApiUsageException("Non-terminated named parameter declaration " +
126+
"at position " + i + " in statement: " + sql);
127+
}
124128
if (statement[j] == ':' || statement[j] == '{') {
125129
throw new InvalidDataAccessApiUsageException("Parameter name contains invalid character '" +
126130
statement[j] + "' at position " + i + " in statement: " + sql);
127131
}
128132
}
129-
if (j >= statement.length) {
130-
throw new InvalidDataAccessApiUsageException(
131-
"Non-terminated named parameter declaration at position " + i + " in statement: " + sql);
132-
}
133133
if (j - i > 2) {
134134
parameter = sql.substring(i + 2, j);
135135
namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
@@ -202,7 +202,7 @@ private static int addNewNamedParameter(Set<String> namedParameters, int namedPa
202202
}
203203

204204
/**
205-
* Skip over comments and quoted names present in an SQL statement
205+
* Skip over comments and quoted names present in an SQL statement.
206206
* @param statement character array containing SQL statement
207207
* @param position current position of statement
208208
* @return next position to process after any comments or quotes are skipped

spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public boolean isReturnGeneratedKeys() {
211211
* Set the column names of the auto-generated keys.
212212
* @see java.sql.Connection#prepareStatement(String, String[])
213213
*/
214-
public void setGeneratedKeysColumnNames(String... names) {
214+
public void setGeneratedKeysColumnNames(@Nullable String... names) {
215215
if (isCompiled()) {
216216
throw new InvalidDataAccessApiUsageException(
217217
"The column names for the generated keys must be set before the operation is compiled");
@@ -230,7 +230,7 @@ public String[] getGeneratedKeysColumnNames() {
230230
/**
231231
* Set the SQL executed by this operation.
232232
*/
233-
public void setSql(String sql) {
233+
public void setSql(@Nullable String sql) {
234234
this.sql = sql;
235235
}
236236

@@ -297,7 +297,7 @@ public void declareParameter(SqlParameter param) throws InvalidDataAccessApiUsag
297297
* Add one or more declared parameters. Used for configuring this operation
298298
* when used in a bean factory. Each parameter will specify SQL type and (optionally)
299299
* the parameter's name.
300-
* @param parameters Array containing the declared {@link SqlParameter} objects
300+
* @param parameters an array containing the declared {@link SqlParameter} objects
301301
* @see #declaredParameters
302302
*/
303303
public void setParameters(SqlParameter... parameters) {

spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,34 +40,33 @@
4040
*/
4141
public abstract class SqlCall extends RdbmsOperation {
4242

43-
/**
44-
* Object enabling us to create CallableStatementCreators
45-
* efficiently, based on this class's declared parameters.
46-
*/
47-
@Nullable
48-
private CallableStatementCreatorFactory callableStatementFactory;
49-
5043
/**
5144
* Flag used to indicate that this call is for a function and to
5245
* use the {? = call get_invoice_count(?)} syntax.
5346
*/
5447
private boolean function = false;
5548

5649
/**
57-
* Flag used to indicate that the sql for this call should be used exactly as it is
58-
* defined. No need to add the escape syntax and parameter place holders.
50+
* Flag used to indicate that the sql for this call should be used exactly as
51+
* it is defined. No need to add the escape syntax and parameter place holders.
5952
*/
6053
private boolean sqlReadyForUse = false;
6154

6255
/**
6356
* Call string as defined in java.sql.CallableStatement.
64-
* String of form {call add_invoice(?, ?, ?)}
65-
* or {? = call get_invoice_count(?)} if isFunction is set to true
66-
* Updated after each parameter is added.
57+
* String of form {call add_invoice(?, ?, ?)} or {? = call get_invoice_count(?)}
58+
* if isFunction is set to true. Updated after each parameter is added.
6759
*/
6860
@Nullable
6961
private String callString;
7062

63+
/**
64+
* Object enabling us to create CallableStatementCreators
65+
* efficiently, based on this class's declared parameters.
66+
*/
67+
@Nullable
68+
private CallableStatementCreatorFactory callableStatementFactory;
69+
7170

7271
/**
7372
* Constructor to allow use as a JavaBean.
@@ -83,8 +82,8 @@ public SqlCall() {
8382
/**
8483
* Create a new SqlCall object with SQL, but without parameters.
8584
* Must add parameters or settle with none.
86-
* @param ds DataSource to obtain connections from
87-
* @param sql SQL to execute
85+
* @param ds the DataSource to obtain connections from
86+
* @param sql the SQL to execute
8887
*/
8988
public SqlCall(DataSource ds, String sql) {
9089
setDataSource(ds);
@@ -103,7 +102,7 @@ public void setFunction(boolean function) {
103102
* Return whether this call is for a function.
104103
*/
105104
public boolean isFunction() {
106-
return function;
105+
return this.function;
107106
}
108107

109108
/**
@@ -117,7 +116,7 @@ public void setSqlReadyForUse(boolean sqlReadyForUse) {
117116
* Return whether the SQL can be used as is.
118117
*/
119118
public boolean isSqlReadyForUse() {
120-
return sqlReadyForUse;
119+
return this.sqlReadyForUse;
121120
}
122121

123122

@@ -129,30 +128,32 @@ public boolean isSqlReadyForUse() {
129128
@Override
130129
protected final void compileInternal() {
131130
if (isSqlReadyForUse()) {
132-
this.callString = getSql();
131+
this.callString = resolveSql();
133132
}
134133
else {
134+
StringBuilder callString = new StringBuilder(32);
135135
List<SqlParameter> parameters = getDeclaredParameters();
136136
int parameterCount = 0;
137137
if (isFunction()) {
138-
this.callString = "{? = call " + getSql() + "(";
138+
callString.append("{? = call ").append(resolveSql()).append('(');
139139
parameterCount = -1;
140140
}
141141
else {
142-
this.callString = "{call " + getSql() + "(";
142+
callString.append("{call ").append(resolveSql()).append('(');
143143
}
144144
for (SqlParameter parameter : parameters) {
145-
if (!(parameter.isResultsParameter())) {
145+
if (!parameter.isResultsParameter()) {
146146
if (parameterCount > 0) {
147-
this.callString += ", ";
147+
callString.append(", ");
148148
}
149149
if (parameterCount >= 0) {
150-
this.callString += "?";
150+
callString.append('?');
151151
}
152152
parameterCount++;
153153
}
154154
}
155-
this.callString += ")}";
155+
callString.append(")}");
156+
this.callString = callString.toString();
156157
}
157158
if (logger.isDebugEnabled()) {
158159
logger.debug("Compiled stored procedure. Call string is [" + this.callString + "]");

spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterUtilsTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ public void convertTypeMapToSqlParameterList() {
117117
}
118118

119119
@Test(expected = InvalidDataAccessApiUsageException.class)
120-
public void buildValueArrayWithMissingParameterValue() throws Exception {
120+
public void buildValueArrayWithMissingParameterValue() {
121121
String sql = "select count(0) from foo where id = :id";
122122
NamedParameterUtils.buildValueArray(sql, Collections.<String, Object>emptyMap());
123123
}
124124

125125
@Test
126-
public void substituteNamedParametersWithStringContainingQuotes() throws Exception {
126+
public void substituteNamedParametersWithStringContainingQuotes() {
127127
String expectedSql = "select 'first name' from artists where id = ? and quote = 'exsqueeze me?'";
128128
String sql = "select 'first name' from artists where id = :id and quote = 'exsqueeze me?'";
129129
String newSql = NamedParameterUtils.substituteNamedParameters(sql, new MapSqlParameterSource());
130130
assertEquals(expectedSql, newSql);
131131
}
132132

133133
@Test
134-
public void testParseSqlStatementWithStringContainingQuotes() throws Exception {
134+
public void testParseSqlStatementWithStringContainingQuotes() {
135135
String expectedSql = "select 'first name' from artists where id = ? and quote = 'exsqueeze me?'";
136136
String sql = "select 'first name' from artists where id = :id and quote = 'exsqueeze me?'";
137137
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
@@ -173,15 +173,15 @@ public void parseSqlContainingComments() {
173173
}
174174

175175
@Test // SPR-4612
176-
public void parseSqlStatementWithPostgresCasting() throws Exception {
176+
public void parseSqlStatementWithPostgresCasting() {
177177
String expectedSql = "select 'first name' from artists where id = ? and birth_date=?::timestamp";
178178
String sql = "select 'first name' from artists where id = :id and birth_date=:birthDate::timestamp";
179179
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
180180
assertEquals(expectedSql, NamedParameterUtils.substituteNamedParameters(parsedSql, null));
181181
}
182182

183183
@Test // SPR-13582
184-
public void parseSqlStatementWithPostgresContainedOperator() throws Exception {
184+
public void parseSqlStatementWithPostgresContainedOperator() {
185185
String expectedSql = "select 'first name' from artists where info->'stat'->'albums' = ?? ? and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'";
186186
String sql = "select 'first name' from artists where info->'stat'->'albums' = ?? :album and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'";
187187
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
@@ -190,7 +190,7 @@ public void parseSqlStatementWithPostgresContainedOperator() throws Exception {
190190
}
191191

192192
@Test // SPR-15382
193-
public void parseSqlStatementWithPostgresAnyArrayStringsExistsOperator() throws Exception {
193+
public void parseSqlStatementWithPostgresAnyArrayStringsExistsOperator() {
194194
String expectedSql = "select '[\"3\", \"11\"]'::jsonb ?| '{1,3,11,12,17}'::text[]";
195195
String sql = "select '[\"3\", \"11\"]'::jsonb ?| '{1,3,11,12,17}'::text[]";
196196

@@ -200,7 +200,7 @@ public void parseSqlStatementWithPostgresAnyArrayStringsExistsOperator() throws
200200
}
201201

202202
@Test // SPR-15382
203-
public void parseSqlStatementWithPostgresAllArrayStringsExistsOperator() throws Exception {
203+
public void parseSqlStatementWithPostgresAllArrayStringsExistsOperator() {
204204
String expectedSql = "select '[\"3\", \"11\"]'::jsonb ?& '{1,3,11,12,17}'::text[] AND ? = 'Back in Black'";
205205
String sql = "select '[\"3\", \"11\"]'::jsonb ?& '{1,3,11,12,17}'::text[] AND :album = 'Back in Black'";
206206

@@ -210,7 +210,7 @@ public void parseSqlStatementWithPostgresAllArrayStringsExistsOperator() throws
210210
}
211211

212212
@Test // SPR-7476
213-
public void parseSqlStatementWithEscapedColon() throws Exception {
213+
public void parseSqlStatementWithEscapedColon() {
214214
String expectedSql = "select '0\\:0' as a, foo from bar where baz < DATE(? 23:59:59) and baz = ?";
215215
String sql = "select '0\\:0' as a, foo from bar where baz < DATE(:p1 23\\:59\\:59) and baz = :p2";
216216

@@ -223,7 +223,7 @@ public void parseSqlStatementWithEscapedColon() throws Exception {
223223
}
224224

225225
@Test // SPR-7476
226-
public void parseSqlStatementWithBracketDelimitedParameterNames() throws Exception {
226+
public void parseSqlStatementWithBracketDelimitedParameterNames() {
227227
String expectedSql = "select foo from bar where baz = b??z";
228228
String sql = "select foo from bar where baz = b:{p1}:{p2}z";
229229

@@ -236,7 +236,7 @@ public void parseSqlStatementWithBracketDelimitedParameterNames() throws Excepti
236236
}
237237

238238
@Test // SPR-7476
239-
public void parseSqlStatementWithEmptyBracketsOrBracketsInQuotes() throws Exception {
239+
public void parseSqlStatementWithEmptyBracketsOrBracketsInQuotes() {
240240
String expectedSql = "select foo from bar where baz = b:{}z";
241241
String sql = "select foo from bar where baz = b:{}z";
242242
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
@@ -257,7 +257,7 @@ public void parseSqlStatementWithEmptyBracketsOrBracketsInQuotes() throws Except
257257
public void parseSqlStatementWithSingleLetterInBrackets() {
258258
String expectedSql = "select foo from bar where baz = b?z";
259259
String sql = "select foo from bar where baz = b:{p}z";
260-
260+
261261
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
262262
assertEquals(1, parsedSql.getParameterNames().size());
263263
assertEquals("p", parsedSql.getParameterNames().get(0));
@@ -273,14 +273,14 @@ public void parseSqlStatementWithLogicalAnd() {
273273
}
274274

275275
@Test // SPR-2544
276-
public void substituteNamedParametersWithLogicalAnd() throws Exception {
276+
public void substituteNamedParametersWithLogicalAnd() {
277277
String expectedSql = "xxx & yyyy";
278278
String newSql = NamedParameterUtils.substituteNamedParameters(expectedSql, new MapSqlParameterSource());
279279
assertEquals(expectedSql, newSql);
280280
}
281281

282282
@Test // SPR-3173
283-
public void variableAssignmentOperator() throws Exception {
283+
public void variableAssignmentOperator() {
284284
String expectedSql = "x := 1";
285285
String newSql = NamedParameterUtils.substituteNamedParameters(expectedSql, new MapSqlParameterSource());
286286
assertEquals(expectedSql, newSql);

spring-tx/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ protected UserTransaction findUserTransaction() {
709709
* @see #FALLBACK_TRANSACTION_MANAGER_NAMES
710710
*/
711711
@Nullable
712-
protected TransactionManager findTransactionManager(UserTransaction ut) {
712+
protected TransactionManager findTransactionManager(@Nullable UserTransaction ut) {
713713
if (ut instanceof TransactionManager) {
714714
if (logger.isDebugEnabled()) {
715715
logger.debug("JTA UserTransaction object [" + ut + "] implements TransactionManager");
@@ -864,7 +864,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
864864
* <p>Calls {@code applyIsolationLevel} and {@code applyTimeout}
865865
* before invoking the UserTransaction's {@code begin} method.
866866
* @param txObject the JtaTransactionObject containing the UserTransaction
867-
* @param definition TransactionDefinition instance, describing propagation
867+
* @param definition the TransactionDefinition instance, describing propagation
868868
* behavior, isolation level, read-only flag, timeout, and transaction name
869869
* @throws NotSupportedException if thrown by JTA methods
870870
* @throws SystemException if thrown by JTA methods
@@ -1139,7 +1139,7 @@ protected void registerAfterCompletionWithExistingTransaction(
11391139
* If none of the two is available, a warning will be logged.
11401140
* <p>Can be overridden in subclasses, for specific JTA implementations.
11411141
* @param txObject the current transaction object
1142-
* @param synchronizations List of TransactionSynchronization objects
1142+
* @param synchronizations a List of TransactionSynchronization objects
11431143
* @throws RollbackException if thrown by JTA methods
11441144
* @throws SystemException if thrown by JTA methods
11451145
* @see #getTransactionManager()

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/PathResourceLookupFunction.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,8 @@ private boolean isInvalidPath(String path) {
113113
return true;
114114
}
115115
}
116-
if (path.contains("")) {
117-
path = StringUtils.cleanPath(path);
118-
if (path.contains("../")) {
119-
return true;
120-
}
116+
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
117+
return true;
121118
}
122119
return false;
123120
}

0 commit comments

Comments
 (0)