Skip to content

Commit 07b3e92

Browse files
committed
Merge branch '5.2.x'
# Conflicts: # build.gradle # src/docs/asciidoc/core/core-aop-api.adoc
2 parents 29885e2 + 3ec4538 commit 07b3e92

File tree

9 files changed

+69
-50
lines changed

9 files changed

+69
-50
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ configure([rootProject] + javaProjects) { project ->
334334
}
335335

336336
checkstyle {
337-
toolVersion = "8.36"
337+
toolVersion = "8.36.1"
338338
configDirectory.set(rootProject.file("src/checkstyle"))
339339
}
340340

spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -159,8 +159,6 @@ public class MimeMessageHelper {
159159

160160
private static final String HEADER_PRIORITY = "X-Priority";
161161

162-
private static final String HEADER_CONTENT_ID = "Content-ID";
163-
164162

165163
private final MimeMessage mimeMessage;
166164

@@ -175,6 +173,8 @@ public class MimeMessageHelper {
175173

176174
private FileTypeMap fileTypeMap;
177175

176+
private boolean encodeFilenames = true;
177+
178178
private boolean validateAddresses = false;
179179

180180

@@ -464,7 +464,7 @@ protected FileTypeMap getDefaultFileTypeMap(MimeMessage mimeMessage) {
464464
* Set the Java Activation Framework {@code FileTypeMap} to use
465465
* for determining the content type of inline content and attachments
466466
* that get added to the message.
467-
* <p>Default is the {@code FileTypeMap} that the underlying
467+
* <p>The default is the {@code FileTypeMap} that the underlying
468468
* MimeMessage carries, if any, or the Activation Framework's default
469469
* {@code FileTypeMap} instance else.
470470
* @see #addInline
@@ -480,18 +480,40 @@ public void setFileTypeMap(@Nullable FileTypeMap fileTypeMap) {
480480

481481
/**
482482
* Return the {@code FileTypeMap} used by this MimeMessageHelper.
483+
* @see #setFileTypeMap
483484
*/
484485
public FileTypeMap getFileTypeMap() {
485486
return this.fileTypeMap;
486487
}
487488

488489

490+
/**
491+
* Set whether to encode attachment filenames passed to this helper's
492+
* {@code #addAttachment} methods.
493+
* <p>The default is {@code true} for compatibility with older email clients;
494+
* turn this to {@code false} for standard MIME behavior. On a related note,
495+
* check out JavaMail's {@code mail.mime.encodefilename} system property.
496+
* @since 5.2.9
497+
* @see #addAttachment(String, DataSource)
498+
* @see MimeBodyPart#setFileName(String)
499+
*/
500+
public void setEncodeFilenames(boolean encodeFilenames) {
501+
this.encodeFilenames = encodeFilenames;
502+
}
503+
504+
/**
505+
* Return whether to encode attachment filenames passed to this helper's
506+
* {@code #addAttachment} methods.
507+
* @since 5.2.9
508+
* @see #setEncodeFilenames
509+
*/
510+
public boolean isEncodeFilenames() {
511+
return this.encodeFilenames;
512+
}
513+
489514
/**
490515
* Set whether to validate all addresses which get passed to this helper.
491-
* Default is "false".
492-
* <p>Note that this is by default just available for JavaMail >= 1.3.
493-
* You can override the default {@code validateAddress method} for
494-
* validation on older JavaMail versions (or for custom validation).
516+
* <p>The default is {@code false}.
495517
* @see #validateAddress
496518
*/
497519
public void setValidateAddresses(boolean validateAddresses) {
@@ -500,6 +522,7 @@ public void setValidateAddresses(boolean validateAddresses) {
500522

501523
/**
502524
* Return whether this helper will validate all addresses passed to it.
525+
* @see #setValidateAddresses
503526
*/
504527
public boolean isValidateAddresses() {
505528
return this.validateAddresses;
@@ -508,10 +531,8 @@ public boolean isValidateAddresses() {
508531
/**
509532
* Validate the given mail address.
510533
* Called by all of MimeMessageHelper's address setters and adders.
511-
* <p>Default implementation invokes {@code InternetAddress.validate()},
534+
* <p>The default implementation invokes {@link InternetAddress#validate()},
512535
* provided that address validation is activated for the helper instance.
513-
* <p>Note that this method will just work on JavaMail >= 1.3. You can override
514-
* it for validation on older JavaMail versions or for custom validation.
515536
* @param address the address to validate
516537
* @throws AddressException if validation failed
517538
* @see #isValidateAddresses()
@@ -525,7 +546,8 @@ protected void validateAddress(InternetAddress address) throws AddressException
525546

526547
/**
527548
* Validate all given mail addresses.
528-
* Default implementation simply delegates to validateAddress for each address.
549+
* <p>The default implementation simply delegates to {@link #validateAddress}
550+
* for each address.
529551
* @param addresses the addresses to validate
530552
* @throws AddressException if validation failed
531553
* @see #validateAddress(InternetAddress)
@@ -885,9 +907,7 @@ public void addInline(String contentId, DataSource dataSource) throws MessagingE
885907
Assert.notNull(dataSource, "DataSource must not be null");
886908
MimeBodyPart mimeBodyPart = new MimeBodyPart();
887909
mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
888-
// We're using setHeader here to remain compatible with JavaMail 1.2,
889-
// rather than JavaMail 1.3's setContentID.
890-
mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
910+
mimeBodyPart.setContentID("<" + contentId + ">");
891911
mimeBodyPart.setDataHandler(new DataHandler(dataSource));
892912
getMimeMultipart().addBodyPart(mimeBodyPart);
893913
}
@@ -997,7 +1017,8 @@ public void addAttachment(String attachmentFilename, DataSource dataSource) thro
9971017
try {
9981018
MimeBodyPart mimeBodyPart = new MimeBodyPart();
9991019
mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
1000-
mimeBodyPart.setFileName(MimeUtility.encodeText(attachmentFilename));
1020+
mimeBodyPart.setFileName(isEncodeFilenames() ?
1021+
MimeUtility.encodeText(attachmentFilename) : attachmentFilename);
10011022
mimeBodyPart.setDataHandler(new DataHandler(dataSource));
10021023
getRootMimeMultipart().addBodyPart(mimeBodyPart);
10031024
}

spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public Charset getDefaultCharset() {
103103
return this.defaultCharset;
104104
}
105105

106+
106107
@Override
107108
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
108109
return (elementType.resolve() == String.class && super.canDecode(elementType, mimeType));
@@ -167,7 +168,6 @@ private Charset getCharset(@Nullable MimeType mimeType) {
167168

168169
/**
169170
* Finds the first match and longest delimiter, {@link EndFrameBuffer} just after it.
170-
*
171171
* @param dataBuffer the buffer to find delimiters in
172172
* @param matcher used to find the first delimiters
173173
* @return a flux of buffers, containing {@link EndFrameBuffer} after each delimiter that was
@@ -221,16 +221,13 @@ private static DataBuffer joinAndStrip(List<DataBuffer> dataBuffers, boolean str
221221
}
222222

223223
DataBuffer result = dataBuffers.get(0).factory().join(dataBuffers);
224-
225224
if (stripDelimiter && matchingDelimiter != null) {
226225
result.writePosition(result.writePosition() - matchingDelimiter.length);
227226
}
228227
return result;
229228
}
230229

231230

232-
233-
234231
/**
235232
* Create a {@code StringDecoder} for {@code "text/plain"}.
236233
* @param stripDelimiter this flag is ignored
@@ -293,8 +290,7 @@ private static class EndFrameBuffer extends DataBufferWrapper {
293290

294291
private static final DataBuffer BUFFER = DefaultDataBufferFactory.sharedInstance.wrap(new byte[0]);
295292

296-
private byte[] delimiter;
297-
293+
private final byte[] delimiter;
298294

299295
public EndFrameBuffer(byte[] delimiter) {
300296
super(BUFFER);
@@ -304,7 +300,6 @@ public EndFrameBuffer(byte[] delimiter) {
304300
public byte[] delimiter() {
305301
return this.delimiter;
306302
}
307-
308303
}
309304

310305

@@ -313,7 +308,6 @@ private static class LimitChecker implements Consumer<DataBuffer> {
313308
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
314309
private final LimitedDataBufferList list;
315310

316-
317311
LimitChecker(int maxInMemorySize) {
318312
this.list = new LimitedDataBufferList(maxInMemorySize);
319313
}

spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -30,9 +30,9 @@
3030
*/
3131
final class StringToBooleanConverter implements Converter<String, Boolean> {
3232

33-
private static final Set<String> trueValues = new HashSet<>(4);
33+
private static final Set<String> trueValues = new HashSet<>(8);
3434

35-
private static final Set<String> falseValues = new HashSet<>(4);
35+
private static final Set<String> falseValues = new HashSet<>(8);
3636

3737
static {
3838
trueValues.add("true");
@@ -46,6 +46,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> {
4646
falseValues.add("0");
4747
}
4848

49+
4950
@Override
5051
public Boolean convert(String source) {
5152
String value = source.trim();

spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -19,6 +19,7 @@
1919
import java.util.UUID;
2020

2121
import org.springframework.core.convert.converter.Converter;
22+
import org.springframework.lang.Nullable;
2223
import org.springframework.util.StringUtils;
2324

2425
/**
@@ -31,6 +32,7 @@
3132
final class StringToUUIDConverter implements Converter<String, UUID> {
3233

3334
@Override
35+
@Nullable
3436
public UUID convert(String source) {
3537
return (StringUtils.hasText(source) ? UUID.fromString(source.trim()) : null);
3638
}

spring-web/src/main/java/org/springframework/http/ContentDisposition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ public interface Builder {
562562

563563
private static class BuilderImpl implements Builder {
564564

565-
private String type;
565+
private final String type;
566566

567567
@Nullable
568568
private String name;

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ public List<String> getConnection() {
861861
public void setContentDispositionFormData(String name, @Nullable String filename) {
862862
Assert.notNull(name, "Name must not be null");
863863
ContentDisposition.Builder disposition = ContentDisposition.builder("form-data").name(name);
864-
if (filename != null) {
864+
if (StringUtils.hasText(filename)) {
865865
disposition.filename(filename);
866866
}
867867
setContentDisposition(disposition.build());
@@ -888,7 +888,7 @@ public void setContentDisposition(ContentDisposition contentDisposition) {
888888
*/
889889
public ContentDisposition getContentDisposition() {
890890
String contentDisposition = getFirst(CONTENT_DISPOSITION);
891-
if (contentDisposition != null) {
891+
if (StringUtils.hasText(contentDisposition)) {
892892
return ContentDisposition.parse(contentDisposition);
893893
}
894894
return ContentDisposition.empty();

src/docs/asciidoc/core/core-aop-api.adoc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ The `MethodMatcher` interface is normally more important. The complete interface
103103
The `matches(Method, Class)` method is used to test whether this pointcut ever
104104
matches a given method on a target class. This evaluation can be performed when an AOP
105105
proxy is created to avoid the need for a test on every method invocation. If the
106-
two-argument `matches` method returns `true` for a given method, and the `isRuntime()` method
107-
for the MethodMatcher returns `true`, the three-argument matches method is invoked on
108-
every method invocation. This lets a pointcut look at the arguments passed to the
109-
method invocation immediately before the target advice starts.
106+
two-argument `matches` method returns `true` for a given method, and the `isRuntime()`
107+
method for the MethodMatcher returns `true`, the three-argument matches method is
108+
invoked on every method invocation. This lets a pointcut look at the arguments passed
109+
to the method invocation immediately before the target advice starts.
110110

111-
Most `MethodMatcher` implementations are static, meaning that their `isRuntime()` method returns `false`.
112-
In this case, the three-argument `matches` method is never invoked.
111+
Most `MethodMatcher` implementations are static, meaning that their `isRuntime()` method
112+
returns `false`. In this case, the three-argument `matches` method is never invoked.
113113

114114
TIP: If possible, try to make pointcuts static, allowing the AOP framework to cache the
115115
results of pointcut evaluation when an AOP proxy is created.
@@ -145,20 +145,20 @@ See the <<aop, previous chapter>> for a discussion of supported AspectJ pointcut
145145
[[aop-api-pointcuts-impls]]
146146
=== Convenience Pointcut Implementations
147147

148-
Spring provides several convenient pointcut implementations. You can use some of them directly.
149-
Others are intended to be subclassed in application-specific pointcuts.
148+
Spring provides several convenient pointcut implementations. You can use some of them
149+
directly; others are intended to be subclassed in application-specific pointcuts.
150150

151151

152152
[[aop-api-pointcuts-static]]
153153
==== Static Pointcuts
154154

155-
Static pointcuts are based on the method and the target class and cannot take into account the
156-
method's arguments. Static pointcuts suffice -- and are best -- for most usages.
157-
Spring can evaluate a static pointcut only once, when a method is first
158-
invoked. After that, there is no need to evaluate the pointcut again with each method
159-
invocation.
155+
Static pointcuts are based on the method and the target class and cannot take into account
156+
the method's arguments. Static pointcuts suffice -- and are best -- for most usages.
157+
Spring can evaluate a static pointcut only once, when a method is first invoked.
158+
After that, there is no need to evaluate the pointcut again with each method invocation.
160159

161-
The rest of this section describes some of the static pointcut implementations that are included with Spring.
160+
The rest of this section describes some of the static pointcut implementations that are
161+
included with Spring.
162162

163163
[[aop-api-pointcuts-regex]]
164164
===== Regular Expression Pointcuts
@@ -168,9 +168,9 @@ frameworks besides Spring make this possible.
168168
`org.springframework.aop.support.JdkRegexpMethodPointcut` is a generic regular
169169
expression pointcut that uses the regular expression support in the JDK.
170170

171-
With the `JdkRegexpMethodPointcut` class, you can provide a list of pattern strings. If
172-
any of these is a match, the pointcut evaluates to `true`. (So, the result is
173-
effectively the union of these patterns.)
171+
With the `JdkRegexpMethodPointcut` class, you can provide a list of pattern strings.
172+
If any of these is a match, the pointcut evaluates to `true`. (As a consequence,
173+
the resulting pointcut is effectively the union of the specified patterns.)
174174

175175
The following example shows how to use `JdkRegexpMethodPointcut`:
176176

src/docs/asciidoc/core/core-beans.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4424,7 +4424,8 @@ which these `BeanFactoryPostProcessor` instances run by setting the `order` prop
44244424
However, you can only set this property if the `BeanFactoryPostProcessor` implements the
44254425
`Ordered` interface. If you write your own `BeanFactoryPostProcessor`, you should
44264426
consider implementing the `Ordered` interface, too. See the javadoc of the
4427-
{api-spring-framework}/beans/factory/config/BeanFactoryPostProcessor.html[`BeanFactoryPostProcessor`] and {api-spring-framework}/core/Ordered.html[`Ordered`] interfaces for more details.
4427+
{api-spring-framework}/beans/factory/config/BeanFactoryPostProcessor.html[`BeanFactoryPostProcessor`]
4428+
and {api-spring-framework}/core/Ordered.html[`Ordered`] interfaces for more details.
44284429

44294430
[NOTE]
44304431
====

0 commit comments

Comments
 (0)