Commit Graph

1285 Commits

Author SHA1 Message Date
Juergen Hoeller 3ae84d6dd8 Consistent support for Charset/StandardCharsets in UriUtils etc
Issue: SPR-15613
2017-06-12 15:51:45 +02:00
diguage 2efa06237a Use Map#forEach instead of Map#entrySet#forEach
See gh-1449
2017-06-12 14:37:33 +02:00
Arjen Poutsma 9bf82dc18f Add addAll(MultiValueMap)
This commit introduces a new method for MultiValueMap: addAll, which
adds all values of a given map (cf putAll, which replaces existing
values).
2017-06-12 14:12:12 +02:00
Arjen Poutsma 7085a30382 Improve capacity calculcation in DefaultDataBuffer
This commit improves the capacity calculation for the DefaultDataBuffer,
so that the capacity typically doubles instead of improving by the
minimal required amount.

Issue: SPR-15647
2017-06-12 11:04:19 +02:00
Stephane Nicoll 27aabb15f9 Polish "Refact iterator of Map with Java 8 forEach"
Closes gh-1451
2017-06-12 08:53:56 +02:00
diguage dab7a7f0ee Refact iterator of Map with Java 8 forEach
See gh-1451
2017-06-12 08:11:32 +02:00
Juergen Hoeller fd53d2a51a Consistent use of @Nullable in spring-test
This commit also removes nullability from two common spots: ResolvableType.getType() and TargetSource.getTarget(), both of which are never effectively null with any regular implementation. For such scenarios, a non-null empty type/target is the cleaner contract.

Issue: SPR-15540
2017-06-08 22:52:59 +02:00
Juergen Hoeller e6f1950952 Missing @Nullable annotations for findAnnotation/getValue/getDefaultValue
Note that synthesizeAnnotation has an assertion now, keeping its non-null policy.

Issue: SPR-15642
2017-06-08 10:35:54 +02:00
Phillip Webb 72cd24446d Make resolvePropertyName available to subclasses
Change `SystemEnvironmentPropertySource.resolvePropertyName` to a
protected final method so that subclasses may call it.

Issue: SPR-15617
2017-06-07 17:03:31 -07:00
Phillip Webb c675424189 Restore AnnotationUtils null argument support
Update AnnotationUtils to restore support for `null` arguments in
certain methods. Some existing upstream projects were relying on this
behavior.

Issue: SPR-15642
2017-06-07 16:59:24 -07:00
Juergen Hoeller f813712f5b Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments.

Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit.

Issue: SPR-15540
2017-06-07 14:19:15 +02:00
Stephane Nicoll 6e3a9cbbb4 Polish "Refactor duplicated code"
Closes gh-1445
2017-06-04 13:06:09 +02:00
diguage 5288641c50 Refactor duplicated code
See gh-1445
2017-06-04 13:01:03 +02:00
diguage eae63786c2 Fixed reference 2017-06-03 15:19:36 +08:00
Sebastien Deleuze 90df7dd279 Add missing @Nullable annotation
Issue: SPR-15540
2017-06-02 14:16:19 +02:00
Sebastien Deleuze b494c53b40 Avoid defining nullability for non-relevant API
Defining nullability of some API like EnvironmentCapable
or ConditionContext causes issues in Spring Boot because
in the context where they are used, it is known for sure
they will return non-null values even if their API can in
other context return null values.

It is better in this case for both Java and Kotlin to
not define at all the nullabity of such API.

In practice, this is achieved by removing the package level
@NonNullApi annotation and adding it only on the
relevant classes.

Issue: SPR-15540
2017-05-31 22:51:33 +02:00
Sebastien Deleuze 1f28825f9d Add more @Nullable parameters based on null usage
Issue: SPR-15540
2017-05-31 21:42:23 +02:00
Sebastien Deleuze c3e6afb879 Improve null-safety to fix some Spring Boot warnings
Issue: SPR-15540
2017-05-31 17:14:49 +02:00
Sebastien Deleuze b47d713e14 Add missing @Nullable annotations on parameters
Issue: SPR-15540
2017-05-31 16:56:08 +02:00
Sebastien Deleuze ad2c0f8410 Improve @Nullable annotation
This commit makes Spring @Nullable annotation leveraging
JSR 305 @TypeQualifierNickname + @Nonnull(when= When.MAYBE)
instead of directly using @javax.annotation.Nullable which
seems not designed to be used as a meta-annotation.

It also removes @TypeQualifierDefault since the purpose of
this annotation when applied at method level is to only
change return value nullability, not parameters one.

Issue: SPR-15540
2017-05-31 16:56:08 +02:00
Sebastien Deleuze 87598f48e4 Introduce null-safety of Spring Framework API
This commit introduces 2 new @Nullable and @NonNullApi
annotations that leverage JSR 305 (dormant but available via
Findbugs jsr305 dependency and already used by libraries
like OkHttp) meta-annotations to specify explicitly
null-safety of Spring Framework parameters and return values.

In order to avoid adding too much annotations, the
default is set at package level with @NonNullApi and
@Nullable annotations are added when needed at parameter or
return value level. These annotations are intended to be used
on Spring Framework itself but also by other Spring projects.

@Nullable annotations have been introduced based on Javadoc
and search of patterns like "return null;". It is expected that
nullability of Spring Framework API will be polished with
complementary commits.

In practice, this will make the whole Spring Framework API
null-safe for Kotlin projects (when KT-10942 will be fixed)
since Kotlin will be able to leverage these annotations to
know if a parameter or a return value is nullable or not. But
this is also useful for Java developers as well since IntelliJ
IDEA, for example, also understands these annotations to
generate warnings when unsafe nullable usages are detected.

Issue: SPR-15540
2017-05-27 08:57:01 +02:00
Juergen Hoeller db69a082d9 Avoid java.util.Optional signatures for simple field access
Issue: SPR-15576
2017-05-23 22:05:15 +02:00
Juergen Hoeller 7b3f5fd855 ResourceUtils.extractArchiveURL properly deals with top-level war URLs
Issue: SPR-15556
2017-05-17 14:22:43 +02:00
Rossen Stoyanchev 0d28a1c32b Polish 2017-05-05 15:02:09 -04:00
Rossen Stoyanchev 83e0e1604a Refine encoding/decoding exception handling
Starting with removing a package cycle on the use of
ResponseStatusException in the codec package, this commit generally
refines codec exception handling.

The new [Encoding|Decoding]Exception mirror the existing
HttpMessageNot[Readable|Writable]Exception and are used similarly
especially to differentiate betwen 400 and 500 errors when parsing
server request body content.

The commit also aligns some of the exception handling of JSON and XML
on the WebFlux side with that on the Spring MVC side.

Issue: SPR-15516
2017-05-05 14:29:43 -04:00
Juergen Hoeller 652266bcc2 Polishing 2017-05-04 22:27:36 +02:00
Juergen Hoeller d43dfc7bae Properly extract jar file from Tomcat war URL
Issue: SPR-15485
2017-05-03 21:58:59 +02:00
Juergen Hoeller 4d86515fa5 Overridable Commons Logging bridge in separate spring-jcl jar
Issue: SPR-14512
2017-05-03 20:29:05 +02:00
Juergen Hoeller 27057889f8 Polishing 2017-05-03 13:45:29 +02:00
Phillip Webb 07ef7a97c7 Cache SpringFactoriesLoader loads
Update `SpringFactoriesLoader` to cache property file loads. This helps
reduce the number of garbage objects created as each load uses an 8K
char buffer.

Issue: SPR-15509
2017-05-03 12:51:52 +02:00
Arjen Poutsma ed4bd43cac Add writableChannel to WritableResource
This commit introduces a `writableChannel()` method to
`WritableResource`, defaulting to `Channels.newChannel`, but with
overrides for file-based resources.
2017-05-03 11:44:01 +02:00
Juergen Hoeller 9d8e9cf243 Common root cause introspection algorithm in NestedExceptionUtils
Issue: SPR-15510
2017-05-03 11:31:28 +02:00
Juergen Hoeller 817e80c56b Property actually throws exception for no write method found
Issue: SPR-15507
2017-05-02 21:16:31 +02:00
Juergen Hoeller 7ca0094fa1 ResolvableType.clearCache() clears SerializableTypeWrapper cache as well
Issue: SPR-15503
2017-05-02 21:13:55 +02:00
Stephane Nicoll 1b9e12f52f Polish "Use Java 8 forEach method on Map"
Closes gh-1404
2017-04-28 11:07:08 +02:00
Jon Borenstein 13dc0cd828 Use Java 8 forEach method on Map 2017-04-28 11:07:08 +02:00
Juergen Hoeller 1ea54eb2c6 GenericFilterBean lazily initializes its default environment
Alignment with HttpServletBean; consistent use of EnvironmentCapable.

Issue: SPR-15469
2017-04-27 21:38:30 +02:00
Juergen Hoeller baa7b1c6c8 Simplified match condition checks
Issue: SPR-15477
2017-04-27 21:31:50 +02:00
Juergen Hoeller 17f274fd6a Debug log messages for value retrieval exceptions
Issue: SPR-15481
2017-04-27 21:31:39 +02:00
Juergen Hoeller cd95f34666 Merge pull request #1399 from dreis2211/SPR-15477
Optimize AntPathMatcher when checking for potential matches
2017-04-27 20:26:37 +02:00
Christoph Dreis 13b39521d8 Optimize AntPathMatcher when checking for potential matches
Issue: SPR-15477
2017-04-27 19:04:36 +02:00
Sam Brannen c855182e03 Polishing 2017-04-26 18:59:43 +02:00
Juergen Hoeller c668d9a473 Polishing 2017-04-26 18:20:19 +02:00
Juergen Hoeller 3daf626842 Defensive fallback for file system resolution in lastModified()
Issue: SPR-15485
2017-04-26 18:17:00 +02:00
Oleg Zhurakousky 299b9d60fd SPR-15481 Fixed AnnotationUtils.getValue() operation
- Fixed AnnotationUtils.getValue() operation to ensure it re-throws AnnotationConfigurationException instead of swallowing it (as it is done in few other operations in AnnotationUtils)
- Added test
- Removed unnecessary '@SuppressWarnings("unchecked")'
2017-04-26 15:05:32 +02:00
Rossen Stoyanchev cc102c2fcd Properly handle Flux<?> and Flux<Object> in WebFlux
Issue: SPR-15464
2017-04-20 09:19:38 -04:00
Rossen Stoyanchev 7d8dda9a5a Polish reactive type support in Conventions 2017-04-18 23:25:44 -04:00
Rossen Stoyanchev 5c502b87ca Support for reactive types in Conventions
Issue: SPR-14915
2017-04-18 23:00:43 -04:00
Rossen Stoyanchev 71966b0777 Polish Conventions 2017-04-18 23:00:43 -04:00
Juergen Hoeller 91df0653fe Polishing 2017-04-17 15:05:34 +02:00
Juergen Hoeller d50dab6ea9 Suppress deprecation warning on JDK 9 (for LogRecord.setMillis)
Includes revised Log methods in log level order, with consistent delegation of fatal->error for log level checks in SLF4J and JUL, a JavaUtilDelegate for defensive access to java.logging on JDK 9, support for LogRecord message objects, as well as revised log setup recommendations.

Issue: SPR-15453
Issue: SPR-14512
2017-04-14 22:43:44 +02:00
Rossen Stoyanchev 1e8c7e55de WebTestClient assert response body with Consumer<B>
Issue: SPR-15421
2017-04-14 16:39:30 -04:00
Juergen Hoeller 0b118322b0 Polishing 2017-04-13 16:17:05 +02:00
Juergen Hoeller 4838f06d5d ASM annotation visitor logs IllegalAccessException at debug level only
Issue: SPR-15442
2017-04-12 18:05:30 +02:00
Juergen Hoeller 093e573ace ASM annotation visitor defensively accesses enum constants
Issue: SPR-15442
2017-04-12 15:36:18 +02:00
Sebastien Deleuze 4d9144132e Upgrade to Reactor Core 3.1
Issue: SPR-15318
2017-04-11 18:13:04 +02:00
Juergen Hoeller b061556f68 LogFactory enforces lazy resolution of non-String messages for SLF4J as well
Issue: SPR-14512
2017-04-11 15:39:17 +02:00
Sebastien Deleuze 23e35c0e1a Handle Jackson InvalidDefinitionException with 5xx status in WebFlux
Issue: SPR-14925
2017-04-11 12:39:09 +02:00
Juergen Hoeller c4e0d6c2a2 UnknownHostException as resource-not-found for properties files
Plus first-class declaration of FileNotFoundException in Resource javadoc.

Issue: SPR-15433
2017-04-11 11:45:30 +02:00
Juergen Hoeller ce4eff321c Optimize StringUtils.replace for larger replacement pattern
Issue: SPR-15430
2017-04-11 11:40:50 +02:00
Juergen Hoeller 3a1d431c7d Optimize StringUtils.replace/deleteAny for common no-op case
Issue: SPR-15430
2017-04-11 10:11:54 +02:00
Juergen Hoeller 7fbc20e225 Undeprecate TypeVariableMap methods on GenericTypeResolver
Issue: SPR-15429
2017-04-11 10:09:09 +02:00
Juergen Hoeller e5fdd4cd1d Extracted AbstractJsonHttpMessageConverter from GsonHttpMessageConverter
Generic type resolution algorithm in GenericTypeResolver shared between Jackson and Gson.

Issue: SPR-15381
2017-04-10 15:36:29 +02:00
Juergen Hoeller ea5cb26d75 LogFactory obtains ClassLoader-specific LoggerContext for Log4J
Issue: SPR-14512
2017-04-07 16:34:12 +02:00
Juergen Hoeller 8cb24e0d93 SettableTask.checkCompletingThread() only resets marker after match
Issue: SPR-15409
2017-04-07 13:39:58 +02:00
Juergen Hoeller 2566d6f5c8 LogFactory differentiates between SLF4J API and SPI presence
Issue: SPR-14512
2017-04-06 17:10:37 +02:00
Juergen Hoeller 702e01ad52 UrlResource applies StringUtils.getFilename against cleaned URL path
Issue: SPR-15411
2017-04-06 14:27:00 +02:00
Juergen Hoeller 67ea4b3a05 package-info for repackaged libraries (and other polishing) 2017-04-06 14:10:46 +02:00
Juergen Hoeller 75dd8d9c06 UrlResource applies StringUtils.getFilename against URL path
Issue: SPR-15411
2017-04-06 14:07:22 +02:00
Juergen Hoeller 3037277d0e Minimize reflective interaction with annotation instances during retrieval
Issue: SPR-15387
2017-04-06 14:07:17 +02:00
Juergen Hoeller 45e7b350bd LogFactory provides getFactory() with getInstance methods as well
Issue: SPR-14512
2017-04-05 22:24:09 +02:00
Juergen Hoeller 47277f43da spring-core provides custom variant of Commons Logging
Includes dependency updates (JavaMail 1.6 RC1, RxJava 2.0.8, Tomcat 8.5.13, Undertow 1.4.12, XNIO 3.4.5)

Issue: SPR-14512
2017-04-05 21:22:44 +02:00
Rossen Stoyanchev ae2306326e Add RxJava1 Reactive Streams adapters check 2017-04-04 12:25:58 -04:00
Juergen Hoeller e9627a10c7 Deprecate ObjectUtils.hashCode for primitives in favor of JDK 8's hashCode methods
Issue: SPR-15395
2017-04-04 17:16:50 +02:00
Rossen Stoyanchev 37f9c86758 Fix failing tests due to last commit 2017-04-03 09:38:08 -04:00
Rossen Stoyanchev 62c1e44db2 Spring MVC supports reactive return values
This commit adds support for reactive library types to be returned
directly from controller methods adapting them either to a
ResponseBodyEmitter (streaming) or DeferredResult (non-streaming).

The reactive libraries supported are the ones that can adapted to a
Reactive Streams Publisher through the ReactiveAdapterRegistry.

Issue: SPR-15365
2017-04-03 09:01:49 -04:00
Sebastien Deleuze cbd98d5247 Switch back to Reactor BOM Aluminium-BUILD-SNAPSHOT 2017-03-29 16:41:54 +02:00
stonio 90388e4701 Replace size() check with isEmpty()
Closes gh-1333
2017-03-27 15:34:23 +02:00
stonio 412947a53f Polish CollectionFactoryTests
Closes gh-1334
2017-03-27 12:51:11 +02:00
Rossen Stoyanchev 0662dbf044 String decoding for text only vs any MIME type
Follow-up to:
3d68c496f1

StringDecoder can be created in text-only vs "*/*" mode which in turn
allows a more intuitive order of client side decoders, e.g. SSE does
not have to be ahead of StringDecoder.

The commit also explicitly disables String from the supported types in
Jackson2Decoder leaving it to the StringDecoder in "*/*" mode which
comes after. This does not change the current arrangement since the
the StringDecoder ahead having "*/*" picks up JSON content just the
same.

From a broader perspective this change allows any decoder to deal with
String if it wants to after examining the content type be it the SSE
or another, custom decoder. For Jackson there is very little value in
decoding to String which works only if the output contains a single
JSON string but will fail to parse anything else (JSON object/array)
while StringDecoder in "*/*" mode will not fail.

Issue: SPR-15374
2017-03-23 16:53:06 -04:00
Rossen Stoyanchev 3d68c496f1 String encoding for any MIME type
CharSequenceEncoder now supports all MIME types, however since encoding
Flux<String> can overlap with other encoders (e.g. SSE) there are now
two ways to create a CharSequenceEncoder -- with support for text/plain
only or with support for any MIME type.

In WebFlux configuration we insert one CharSequenceEncoder for
text/plain (as we have so far) and a second instance with support for
any MIME type at the very end.

Issue: SPR-15374
2017-03-22 18:01:32 -04:00
Juergen Hoeller e892e02f41 Polishing 2017-03-21 17:44:47 +01:00
Rossen Stoyanchev c8671041f1 EncoderHttpMessageWriter supports streaming MediaTypes
Support for flushing in EncoderHttpMessageWriter is now driven from a
configurable list of "streaming" media types with the list including
"application/stream+json" by default.

As a result Jackson2ServerHttpMessageWriter is no longer needed.
2017-03-21 10:15:56 -04:00
Rossen Stoyanchev 6f075c9060 Update after changed method in Reactor Core 2017-03-20 21:57:17 -04:00
Juergen Hoeller ab7db413c6 DefaultResponseErrorHandler delegate methods declared as protected
Also revises copyToByteArray/String in FileCopyUtils/StreamUtils for lenient null handling.

Issue: SPR-15329
2017-03-16 18:57:13 +01:00
Juergen Hoeller 012c56a1f0 Avoid pattern misdetection in Tomcat "war:" URL separator
Issue: SPR-15332
2017-03-16 18:55:49 +01:00
Juergen Hoeller 899f235998 Detect Tomcat's "war" protocol as jar URL
Issue: SPR-15332
2017-03-14 15:19:02 +01:00
Brian Clozel b799013567 Update to Reactor Aluminium SNAPSHOT
Currently the BOM versions are:

* reactor-core 3.0.6.BUILD-SNAPSHOT
* reactor-netty 0.6.2.BUILD-SNAPSHOT

This commit fixes as well a few deprecations in reactor-core.
2017-03-10 15:20:40 +01:00
Arjen Poutsma 63118c1ea7 Add DataBufferUtils.read w/ AsynchFileChannel
This commit adds an overloaded DataBufferUtils.read method that operates
on a AsynchronousFileChannel (as opposed to a ReadableByteChannel, which
already existed). This commit also uses said method in the Resource
encoders, if the Resource is a file.
2017-03-09 14:08:40 +01:00
Juergen Hoeller 94a7624c1f Polishing 2017-03-07 15:42:04 +01:00
Juergen Hoeller 8992f5924f AnnotationUtils makes use of Java 8 getDeclaredAnnotation method
Issue: SPR-15287
2017-02-28 13:07:03 +01:00
Juergen Hoeller cbd19153c4 Polishing 2017-02-22 16:53:54 +01:00
Juergen Hoeller f4de1ea147 Polishing 2017-02-22 15:32:19 +01:00
Juergen Hoeller 6108ab1c31 Test for expected behavior of getAllMergedAnnotations vs findAllMergedAnnotations
Issue: SPR-15271
2017-02-22 15:28:34 +01:00
stonio 7d062df992 Use String#isEmpty()
Closes gh-1335
2017-02-22 11:55:17 +01:00
Stephane Nicoll 598d9a4b05 Add test to reproduce SPR-15271 2017-02-20 11:34:08 +01:00
Juergen Hoeller 45df1d9fea Javadoc fixes 2017-02-18 01:43:30 +01:00
Juergen Hoeller 9543384d9e Avoid deprecated comparators in tests
Issue: SPR-14779
2017-02-16 15:36:27 +01:00
Juergen Hoeller f90cd7705f Consistent ordering of Assert variants
Issue: SPR-15196
2017-02-16 15:32:07 +01:00
Juergen Hoeller 22322fde26 Revised isInstanceOf/isAssignable message concatenation
Issue: SPR-15196
2017-02-16 13:13:20 +01:00