Skip to content

Commit 94e3210

Browse files
committed
Fix nullability warnings and javadoc-triggered package cycles
1 parent 56eadff commit 94e3210

File tree

10 files changed

+48
-38
lines changed

10 files changed

+48
-38
lines changed

spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private void deactivatePatternCache() {
168168

169169

170170
@Override
171-
public boolean isPattern(String path) {
171+
public boolean isPattern(@Nullable String path) {
172172
if (path == null) {
173173
return false;
174174
}
@@ -207,10 +207,10 @@ public boolean matchStart(String pattern, String path) {
207207
* as far as the given base path goes is sufficient)
208208
* @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
209209
*/
210-
protected boolean doMatch(String pattern, String path, boolean fullMatch,
210+
protected boolean doMatch(String pattern, @Nullable String path, boolean fullMatch,
211211
@Nullable Map<String, String> uriTemplateVariables) {
212212

213-
if ((path == null) || (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator))) {
213+
if (path == null || path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
214214
return false;
215215
}
216216

@@ -220,7 +220,6 @@ protected boolean doMatch(String pattern, String path, boolean fullMatch,
220220
}
221221

222222
String[] pathDirs = tokenizePath(path);
223-
224223
int pattIdxStart = 0;
225224
int pattIdxEnd = pattDirs.length - 1;
226225
int pathIdxStart = 0;

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/DestinationVariable.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -26,13 +26,12 @@
2626
* Annotation that indicates a method parameter should be bound to a template variable
2727
* in a destination template string. Supported on message handling methods such as
2828
* {@link MessageMapping @MessageMapping}.
29-
* <p>
30-
* A {@code @DestinationVariable} template variable is always required.
29+
*
30+
* <p>A {@code @DestinationVariable} template variable is always required.
3131
*
3232
* @author Brian Clozel
3333
* @author Rossen Stoyanchev
3434
* @since 4.0
35-
*
3635
* @see org.springframework.messaging.handler.annotation.MessageMapping
3736
* @see org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler
3837
*/

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMapping.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.lang.annotation.Target;
2424

2525
import org.springframework.messaging.Message;
26-
import org.springframework.messaging.simp.annotation.SendToUser;
2726

2827
/**
2928
* Annotation for mapping a {@link Message} onto a message-handling method by
@@ -65,11 +64,11 @@
6564
* authenticated user.</li>
6665
* </ul>
6766
*
68-
* <p>How the return value is handled depends on the processing scenario.
69-
* For STOMP over WebSocket, it is turned into a message and sent to a default
70-
* response destination or to a custom destination specified with an
71-
* {@link SendTo @SendTo} or {@link SendToUser @SendToUser} annotation.
72-
* For RSocket, the response is used to reply to the stream request.
67+
* <p>How the return value is handled depends on the processing scenario. For
68+
* STOMP over WebSocket, it is turned into a message and sent to a default response
69+
* destination or to a custom destination specified with an {@link SendTo @SendTo}
70+
* or {@link org.springframework.messaging.simp.annotation.SendToUser @SendToUser}
71+
* annotation. For RSocket, the response is used to reply to the stream request.
7372
*
7473
* <p>Specializations of this annotation including
7574
* {@link org.springframework.messaging.simp.annotation.SubscribeMapping @SubscribeMapping} or

spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/DefaultClientResponderFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*/
3636
class DefaultClientResponderFactory implements ClientResponderFactory, ClientResponderFactory.Config {
3737

38+
@Nullable
3839
private List<Object> handlers;
3940

4041
@Nullable
@@ -52,9 +53,10 @@ class DefaultClientResponderFactory implements ClientResponderFactory, ClientRes
5253
@Nullable
5354
private ArgumentResolverConfigurer argumentResolverConfigurer;
5455

56+
5557
@Override
5658
public ClientResponderFactory handlers(Object... handlers) {
57-
Assert.notEmpty(handlers, "handlers should not be empty");
59+
Assert.notEmpty(handlers, "Handlers array must not be empty");
5860
this.handlers = Arrays.asList(handlers);
5961
return this;
6062
}
@@ -89,9 +91,10 @@ public ClientResponderFactory.Config argumentResolver(ArgumentResolverConfigurer
8991
return this;
9092
}
9193

94+
9295
@Override
9396
public void accept(RSocketFactory.ClientRSocketFactory clientRSocketFactory) {
94-
Assert.notEmpty(this.handlers, "handlers should not be empty");
97+
Assert.state(this.handlers != null, "No handlers set");
9598
RSocketMessageHandler messageHandler = new RSocketMessageHandler();
9699
messageHandler.setHandlers(this.handlers);
97100
if (this.strategies != null) {

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ public String getContentAsString() throws UnsupportedEncodingException {
232232
* @see #getContentAsString()
233233
*/
234234
public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException {
235-
return isCharset() ?
235+
return (isCharset() && this.characterEncoding != null ?
236236
this.content.toString(this.characterEncoding) :
237-
this.content.toString(fallbackCharset.name());
237+
this.content.toString(fallbackCharset.name()));
238238
}
239239

240240
@Override

spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ protected String serializeForm(MultiValueMap<String, Object> formData, Charset c
438438
return builder.toString();
439439
}
440440

441-
private void writeMultipart(MultiValueMap<String, Object> parts, MediaType contentType, HttpOutputMessage outputMessage)
441+
private void writeMultipart(
442+
MultiValueMap<String, Object> parts, @Nullable MediaType contentType, HttpOutputMessage outputMessage)
442443
throws IOException {
443444

444445
// If the supplied content type is null, fall back to multipart/form-data.

spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ public ControllerAdviceBean(String beanName, BeanFactory beanFactory) {
110110
public ControllerAdviceBean(String beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice) {
111111
Assert.hasText(beanName, "Bean name must contain text");
112112
Assert.notNull(beanFactory, "BeanFactory must not be null");
113-
Assert.isTrue(beanFactory.containsBean(beanName), () -> "BeanFactory [" + beanFactory
114-
+ "] does not contain specified controller advice bean '" + beanName + "'");
113+
Assert.isTrue(beanFactory.containsBean(beanName), () -> "BeanFactory [" + beanFactory +
114+
"] does not contain specified controller advice bean '" + beanName + "'");
115115

116116
this.beanOrName = beanName;
117117
this.beanType = getBeanType(beanName, beanFactory);
118-
this.beanTypePredicate = (controllerAdvice != null ? createBeanTypePredicate(controllerAdvice)
119-
: createBeanTypePredicate(this.beanType));
118+
this.beanTypePredicate = (controllerAdvice != null ? createBeanTypePredicate(controllerAdvice) :
119+
createBeanTypePredicate(this.beanType));
120120
this.beanFactory = beanFactory;
121121
}
122122

@@ -140,8 +140,11 @@ public int getOrder() {
140140
if (resolvedBean instanceof Ordered) {
141141
this.order = ((Ordered) resolvedBean).getOrder();
142142
}
143+
else if (this.beanType != null) {
144+
this.order = OrderUtils.getOrder(this.beanType, Ordered.LOWEST_PRECEDENCE);
145+
}
143146
else {
144-
this.order = OrderUtils.getOrder(getBeanType(), Ordered.LOWEST_PRECEDENCE);
147+
this.order = Ordered.LOWEST_PRECEDENCE;
145148
}
146149
}
147150
return this.order;
@@ -236,18 +239,19 @@ public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext c
236239
return adviceBeans;
237240
}
238241

242+
@Nullable
239243
private static Class<?> getBeanType(String beanName, BeanFactory beanFactory) {
240244
Class<?> beanType = beanFactory.getType(beanName);
241245
return (beanType != null ? ClassUtils.getUserClass(beanType) : null);
242246
}
243247

244-
private static HandlerTypePredicate createBeanTypePredicate(Class<?> beanType) {
248+
private static HandlerTypePredicate createBeanTypePredicate(@Nullable Class<?> beanType) {
245249
ControllerAdvice controllerAdvice = (beanType != null ?
246250
AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class) : null);
247251
return createBeanTypePredicate(controllerAdvice);
248252
}
249253

250-
private static HandlerTypePredicate createBeanTypePredicate(ControllerAdvice controllerAdvice) {
254+
private static HandlerTypePredicate createBeanTypePredicate(@Nullable ControllerAdvice controllerAdvice) {
251255
if (controllerAdvice != null) {
252256
return HandlerTypePredicate.builder()
253257
.basePackage(controllerAdvice.basePackages())

spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,10 @@ public String getContentAsString() throws UnsupportedEncodingException {
231231
* @since 5.2
232232
* @see #getContentAsString()
233233
*/
234-
235234
public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException {
236-
return isCharset() ?
235+
return (isCharset() && this.characterEncoding != null ?
237236
this.content.toString(this.characterEncoding) :
238-
this.content.toString(fallbackCharset.name());
237+
this.content.toString(fallbackCharset.name()));
239238
}
240239

241240
@Override

spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void setEngine(ScriptEngine engine) {
124124

125125
/**
126126
* See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation.
127+
* @since 5.2
127128
*/
128129
public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) {
129130
this.engineSupplier = engineSupplier;
@@ -276,8 +277,9 @@ protected ScriptEngine createEngineFromName(String engineName) {
276277
}
277278

278279
private ScriptEngine createEngineFromSupplier() {
280+
Assert.state(this.engineSupplier != null, "No engine supplier available");
279281
ScriptEngine engine = this.engineSupplier.get();
280-
if (this.renderFunction != null && engine != null) {
282+
if (this.renderFunction != null) {
281283
Assert.isInstanceOf(Invocable.class, engine,
282284
"ScriptEngine must implement Invocable when 'renderFunction' is specified");
283285
}

spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public void setEngine(ScriptEngine engine) {
144144

145145
/**
146146
* See {@link ScriptTemplateConfigurer#setEngineSupplier(Supplier)} documentation.
147+
* @since 5.2
147148
*/
148149
public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) {
149150
this.engineSupplier = engineSupplier;
@@ -286,9 +287,8 @@ protected ScriptEngine getEngine() {
286287
engines = new HashMap<>(4);
287288
enginesHolder.set(engines);
288289
}
289-
String name = (this.engineName != null ? this.engineName : this.engineSupplier.getClass().getSimpleName());
290-
Object engineKey = (!ObjectUtils.isEmpty(this.scripts) ?
291-
new EngineKey(name, this.scripts) : name);
290+
String name = (this.engineName != null ? this.engineName : "");
291+
Object engineKey = (!ObjectUtils.isEmpty(this.scripts) ? new EngineKey(name, this.scripts) : name);
292292
ScriptEngine engine = engines.get(engineKey);
293293
if (engine == null) {
294294
if (this.engineName != null) {
@@ -308,18 +308,22 @@ protected ScriptEngine getEngine() {
308308
}
309309
}
310310

311-
protected ScriptEngine createEngineFromName(@Nullable String engineName) {
312-
if (this.scriptEngineManager == null) {
313-
this.scriptEngineManager = new ScriptEngineManager(obtainApplicationContext().getClassLoader());
311+
protected ScriptEngine createEngineFromName(String engineName) {
312+
ScriptEngineManager scriptEngineManager = this.scriptEngineManager;
313+
if (scriptEngineManager == null) {
314+
scriptEngineManager = new ScriptEngineManager(obtainApplicationContext().getClassLoader());
315+
this.scriptEngineManager = scriptEngineManager;
314316
}
315-
ScriptEngine engine = StandardScriptUtils.retrieveEngineByName(this.scriptEngineManager, engineName);
317+
318+
ScriptEngine engine = StandardScriptUtils.retrieveEngineByName(scriptEngineManager, engineName);
316319
loadScripts(engine);
317320
return engine;
318321
}
319322

320323
private ScriptEngine createEngineFromSupplier() {
324+
Assert.state(this.engineSupplier != null, "No engine supplier available");
321325
ScriptEngine engine = this.engineSupplier.get();
322-
if (this.renderFunction != null && engine != null) {
326+
if (this.renderFunction != null) {
323327
Assert.isInstanceOf(Invocable.class, engine,
324328
"ScriptEngine must implement Invocable when 'renderFunction' is specified");
325329
}

0 commit comments

Comments
 (0)