Commit Graph

1702 Commits

Author SHA1 Message Date
Juergen Hoeller 3431b2330a Avoid unnecessary parameter name inspection for factory method type check
Closes gh-30103
See gh-29612
2023-03-10 19:19:19 +01:00
Sam Brannen 99e54fec3a Ensure all packages declare package-info.java with null-safety annotations
This commit picks up where the two previous commits left off.

Specifically, this commit:

- Removes the "severity=warning" configuration to ensure that violations
  actually fail the build.
- Fixes regular expressions for suppressions by matching forward
  slashes using `[\\/]` instead of `\/`.
- Moves the configuration for newly introduced checks to locations in
  checkstyle.xml that align with the existing organization of that file.
- Renames the IDs for RegexpSinglelineJava checks from
  javaDocPackageNonNullApiAnnotation/javaDocPackageNonNullFieldsAnnotation
  to packageLevelNonNullApiAnnotation/packageLevelNonNullFieldsAnnotation,
  respectively, since these checks are not related to Javadoc.
- Simplifies the null-safety annotation checks to match against
  imported annotation types, which enforces consistency across
  package-info.java files for the annotation declarations.
- Simplifies the RegEx for JavadocPackage suppressions to only exclude
  packages not under src/main/java (vs src/main) and those in the
  framework-docs module.
- Consistently suppresses all checks for the `asm`, `cglib`, `objenesis`,
  and `javapoet` packages in spring-core.
- Adds explicit suppressions for null-safety annotations for the `lang`
  package in spring-core.
- Adds explicit suppressions for null-safety annotations for the
  `org.aopalliance` package in spring-aop.
- Revises the RegEx for null-safety annotation suppressions to only
  exclude package-info.java files not under src/main/java and
  additionally to exclude package-info.java files in the framework-docs
  module as well as those in the spring-context-indexer,
  spring-instrument, and spring-jcl modules.
- Adds all missing package-info.java files.
- Adds null-safety annotations to package-info.java files where
  appropriate.

Closes gh-30069
2023-03-10 17:33:52 +01:00
Sam Brannen 2e5d0470dc Polishing 2023-03-09 14:19:59 +01:00
liupeng d2868f5dd0 Use Set to track ignored properties in BeanUtils.copyProperties()
Closes gh-30088
2023-03-09 14:11:22 +01:00
Juergen Hoeller 95710646d1 Pass pre-determined merged bean definition into InstanceSupplier (for inner beans)
Replaces useless protected obtainFromSupplier method with obtainInstanceFromSupplier.
Moves InstanceSupplier handling to appropriate subclass (DefaultListableBeanFactory).
BeanInstanceSupplier throws BeanInstantiationException instead of BeanCreationException.

Closes gh-29803
2023-03-08 16:49:25 +01:00
Sébastien Deleuze c20efba45c End javadoc generated AOT with a period consistently
Closes gh-29357
2023-03-07 11:20:37 +01:00
Sam Brannen d9500e60a1 Apply "instanceof pattern matching" in remainder of spring-beans module
See gh-30067
2023-03-05 19:09:32 +01:00
Juergen Hoeller f8cb0fa2a0 Custom resolution of preferred constructors for createBean(Class)
Avoids side effects of traditional AUTOWIRE_CONSTRUCTOR algorithm.

Closes gh-30041
2023-03-02 12:54:26 +01:00
Sam Brannen 00c2c1d2a1 Polish "Support @Value for record injection"
See gh-28774
2023-02-28 13:12:15 +01:00
nanfeng 7c9fc575ff Support @Value for record injection
Add @Value support for record injection by disabling populateBean() for
records, since records are immutable.

See gh-28770
Closes gh-28774
2023-02-28 13:01:13 +01:00
Sam Brannen 2e1374b459 Update copyright headers 2023-02-19 13:41:36 +01:00
Sébastien Deleuze ac521a366a Refine instance supplier check in BeanDefinitionMethodGenerator
This commit refines the instance supplier check in
BeanDefinitionMethodGenerator constructor in order to allow
overriding by an AOT contribution.

Closes gh-29556
2023-02-15 09:32:00 +01:00
Johnny Lim 431ae03447 Polish
Closes gh-29928
2023-02-09 09:54:19 +01:00
Juergen Hoeller 16937c7ce5 Polishing 2023-01-31 18:15:28 +01:00
Juergen Hoeller c0c9ba5c2c Polishing 2023-01-31 16:14:32 +01:00
Sam Brannen 75046bbea0 Update copyright headers 2023-01-28 20:42:21 +01:00
Sam Brannen 8e2eeb5364 Apply "instanceof pattern matching" in spring-beans 2023-01-27 17:54:03 +01:00
Sébastien Deleuze 1e47f31210 Support code generation for Set with non-comparable elements
Closes gh-29792
2023-01-23 10:55:34 +01:00
Sam Brannen 58872c79ee Update copyright headers 2023-01-20 14:17:53 +01:00
Sam Brannen 24f18275dd Stop referring to "Spring 3.x" features in documentation and code 2023-01-20 14:13:18 +01:00
Juergen Hoeller 0e8838db90 Flexible constructor resolution in AutowireCapableBeanFactory.createBean(Class)
Closes gh-29855
See gh-29823
2023-01-19 17:10:42 +01:00
Sébastien Deleuze ab0d1c395d Fail explicitly in AOT transformations of instance supplier
It is by design not possible to generate code that handles
bean definitions with user-provided instance suppliers because
the JVM does not allow to get a stable reference reusable at
runtime on the lambda or method reference in the code generated
AOT.

Before this commit, such instance supplier was ignored.
After this commit, an IllegalArgumentException is thrown,
allowing projects to be aware this is not supported and enforce
related refactorings.

The related issue gh-29555 describes how this limitation could
be relaxed in the future.

Closes gh-29556
2023-01-19 16:45:52 +01:00
Sam Brannen 0502d18e3d Update copyright headers 2023-01-19 16:20:03 +01:00
Sam Brannen c4c786596f Migrate to Mockito.mock(T...) where feasible 2023-01-19 16:20:02 +01:00
Sam Brannen e4b25ab480 Polishing 2023-01-19 14:35:27 +01:00
Sam Brannen 64de6de725 Update copyright headers 2023-01-17 15:49:26 +01:00
Sam Brannen ad5c636aff Upgrade to Mockito 5.0 2023-01-17 14:31:11 +01:00
Sam Brannen a4956dfe26 Update copyright headers 2023-01-11 13:52:20 +01:00
Krzysztof Krason afb8a0d1b1 Use new Java features (switch expressions, text blocks, new JDK methods)
Closes gh-29747
2023-01-11 13:51:28 +01:00
Sam Brannen 8dbdfb0449 Polishing 2023-01-10 16:08:02 +01:00
Sam Brannen d5fb5d029b Polish contribution 2023-01-10 16:07:48 +01:00
Vasiliy Kudriavtsev 3738a45658 Avoid wasted memory on empty maps and sets
This commit avoids wasted memory on empty hash maps in
MergedAnnotationReadingVisitor and empty sets in InjectionMetadata.

Closes gh-29742
2023-01-10 15:52:17 +01:00
Juergen Hoeller 254c3725e2 Polishing 2022-12-23 15:14:11 +01:00
Sam Brannen 8df4f927fd Polish contribution
See gh-29697
2022-12-17 11:10:44 +01:00
Simon Baslé 5965917d16 Extract ResourceEntityResolver HTTPS schema resolution fallback
This commit extracts the DTD/XSD remote lookup fallback from the
resolveEntity() method into a protected method.

A WARN-level logging statement is added to the extracted fallback in
order to make it clear that remote lookup happened.

Overriding the protected method would allow users to avoid this
fallback entirely if it isn't desirable, without the need to duplicate
the local resolution code.

Closes gh-29697
2022-12-17 10:34:15 +01:00
Juergen Hoeller d74191427e Avoid NPE on BeanDescriptor access with SimpleBeanInfoFactory
Closes gh-29681
2022-12-13 11:07:22 +01:00
Sam Brannen 46fc28fd1a Clean up Javadoc and source code regarding " ." typos 2022-12-12 16:31:14 +01:00
Brian Clozel 9712bb62fd Upgrade optional dependencies 2022-12-12 14:58:21 +01:00
Sam Brannen 69f47e7700 Polishing
- primarily automated "clean up" using Eclipse IDE
2022-12-09 00:56:00 -05:00
Juergen Hoeller d5732fed45 Polishing 2022-12-01 17:46:31 +01:00
Juergen Hoeller 4c7b04e32a Use resolved factory method return type for supplier code generation
Closes gh-29598
2022-12-01 17:46:23 +01:00
Juergen Hoeller e47978e168 Avoid unnecessary parameter name inspection for constructor-arg resolution
Closes gh-29612
2022-12-01 15:47:12 +01:00
Sam Brannen ad60164911 Update copyright headers for source code changed since August 2022
The changes in this commit were performed using the newly introduced
update_copyright_headers.sh script.
2022-11-29 19:38:42 +01:00
Sam Brannen a88dbbec98 Apply project formatting rules for ternary operator
Discovered via RegEx: ^\s+\?
2022-11-29 17:51:13 +01:00
Juergen Hoeller 8e5eb84da1 Consistently register CGLIB hints for lazy resolution proxy classes
Core JDK/CGLIB proxy registration code extracted to ClassHintUtils.

Closes gh-29584
2022-11-26 13:38:34 +01:00
Juergen Hoeller 459e8a1ea5 Deprecate LocalVariableTableParameterNameDiscoverer completely
LocalVariableTableParameterNameDiscoverer is not registered by default anymore now.
Java sources should be compiled with `-parameters` instead (available since Java 8).
Also retaining standard Java parameter names for all of Spring's Kotlin sources now.

Closes gh-29531
2022-11-22 19:26:15 +01:00
Sam Brannen 7fcd1de8e3 Use AssertJ's isEmpty() instead of hasSize(0)
Achieved via global search-and-replace.
2022-11-22 17:11:50 +01:00
Sam Brannen d5b0b2b1a1 User AssertJ's hasSize() for arrays
Achieved via global search-and-replace.
2022-11-22 17:03:45 +01:00
Sam Brannen 36f7597f25 Use AssertJ's hasSize() for collections and maps
Achieved via a global search-and-replace.
2022-11-22 16:50:10 +01:00
Marten Deinum c1dfde5ba4
Fix link to Bean Utils Light Library in BeanUtils Javadoc
The URL for the BULL library has changed (not sure when, probably way back).

This updates it to the correct location.

Closes gh-29534
2022-11-21 16:59:30 +01:00
Sam Brannen 796b8c1278 Polishing 2022-11-18 15:14:14 +01:00
Sam Brannen cefd74555a Polish contribution 2022-11-18 15:07:08 +01:00
wizard e9555d4825 Polish AbstractAutowireCapableBeanFactory and use instanceof pattern matching
Closes gh-29499
2022-11-18 15:00:05 +01:00
Sam Brannen abf3400c07 Use Assert.state() where appropriate 2022-11-15 12:31:10 +01:00
Sam Brannen 2aa78889d2 Use consistent wording in precondition error messages 2022-11-15 12:31:01 +01:00
Stephane Nicoll 711a63adca Polish
See gh-29391
2022-11-15 11:53:01 +01:00
Juergen Hoeller 588a70218a Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
2022-11-14 23:38:10 +01:00
Juergen Hoeller ec3f59e6fe Allow AutoCloseable dereferences on original AutoCloseable beans
Closes gh-29480
2022-11-14 23:37:05 +01:00
Juergen Hoeller 49ee4a4fdf Deprecated unused findAutowireCandidates template method (removed in 6.0)
See gh-29487
2022-11-14 23:35:47 +01:00
Juergen Hoeller 28cd39abf9 Remove unused AutowiredAnnotationBeanPostProcessor template methods
Closes gh-29487
2022-11-14 23:23:39 +01:00
Juergen Hoeller aaeb5eb0d2 Avoid direct URL construction and URL equality checks
Closes gh-29486
2022-11-14 23:23:12 +01:00
Stephane Nicoll da4b539f20 Stop generating generic type as Object for unresolved generics
Closes gh-29454
2022-11-09 12:00:34 +01:00
Juergen Hoeller 70bb785ed6 Turn nested generic FactoryBean type into resolved Class for fallback match
See gh-29385
2022-11-09 11:24:50 +01:00
Juergen Hoeller 0e9eab55ce Unwrap nested generic type within FactoryBean target type if necessary
Closes gh-29385
2022-11-08 20:22:12 +01:00
Sam Brannen f26a7dee97 Fix broken tests, update copyright dates, and polish
See gh-29414
2022-11-08 20:07:53 +01:00
Kulwant Singh b2c8546013 Rely on automatic boxing/unboxing in tests
Closes gh-29414
2022-11-08 19:38:03 +01:00
Sam Brannen d0b162a76c Polishing 2022-11-08 14:16:00 +01:00
Juergen Hoeller 86d45578d9 Introduce findAllAnnotationsOnBean variant on ListableBeanFactory
Closes gh-29446
2022-11-08 13:29:33 +01:00
Sam Brannen 3438c47744 Polishing 2022-11-08 11:48:13 +01:00
Sam Brannen 34b1857236 Avoid String allocations with Assert.state() 2022-11-04 15:51:32 +01:00
Sébastien Deleuze c091bbdeaa Merge branch '5.3.x' 2022-11-02 12:18:15 +01:00
Sébastien Deleuze c14cbd07f4 Use non-null DateFormat for CustomDateEditor in tests
Closes gh-29419
2022-11-02 12:01:49 +01:00
Sébastien Deleuze 403cfefc28 Add AOT processing of bean aliases
This commit adds AOT processing of bean aliases.

Closes gh-29391
2022-11-02 10:07:21 +01:00
Juergen Hoeller 6b6cf1b4a2 Avoid decorated definition bypass for scoped proxy determination
GenericApplicationContext registers proxy hints without any SmartInstantiationAwareBeanPostProcessor involved as well.

Closes gh-29335
2022-10-19 09:55:47 +02:00
Juergen Hoeller cb44e09694 Merge branch '5.3.x' 2022-10-18 16:24:35 +02:00
Juergen Hoeller 4b0bf16389 Select ambiguous write method based on read method (matching its return type)
Also avoids unnecessary checks in name-based PropertyDescriptor constructor.

See gh-29320
2022-10-18 16:17:03 +02:00
Stephane Nicoll 6d688e196d Restore support of list of inner bean definitions
This commit restores the support of multiple bean definitions being
specified in a `List` as a property value or constructor argument.

Rather than handling inner bean definitions externally, there are now
supported by BeanDefinitionPropertiesCodeGenerator, and list of such
type is handled transparently.

Closes gh-29075
2022-10-18 15:28:18 +02:00
Johnny Lim 1ea3f49eba Add missing since on setCurrentlyInvokedFactoryMethod()
See gh-29326
2022-10-18 13:03:13 +02:00
Juergen Hoeller e03abc94ff Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
#	spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java
#	spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java
#	spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
2022-10-17 12:56:19 +02:00
Juergen Hoeller 33023b240f Provide optional SimpleBeanInfoFactory for better introspection performance
Closes gh-29330
2022-10-17 12:25:53 +02:00
Juergen Hoeller c407dc3df8 Reset/rebuild BeanPostProcessorCache within full synchronization
Closes gh-29299
2022-10-17 12:25:35 +02:00
Juergen Hoeller b796b52d4e Extract SimpleBeanInfo adaptation into internal SimpleBeanInfoFactory
See gh-29320
2022-10-14 12:34:43 +02:00
Juergen Hoeller bba313c2f5 Perform basic property determination without java.beans.Introspector
Closes gh-29320
2022-10-13 19:02:45 +02:00
Stephane Nicoll 061fa475ee Avoid generated code in the javax package
This commit updates the existing logic to also exclude code generation
in the javax package.

Closes gh-29123
2022-10-10 15:09:00 +02:00
Sam Brannen 34e5aac0f5 Reintroduce factory method name in exception thrown from SimpleInstantiationStrategy 2022-10-10 14:28:35 +02:00
Sébastien Deleuze 42c3ac64ff Remove spring.spel.ignore and spring.xml.ignore flags
This commit also removes ResourcePropertiesPersister which
was introduced in 5.3 specifically for spring.xml.ignore
flag and which is expected to be used only internally by
Spring Framework. DefaultPropertiesPersister should be used
instead.

Closes gh-29277
2022-10-10 12:11:19 +02:00
Johnny Lim ced37d53b4 Polishing
Closes gh-29284
2022-10-08 13:43:09 +02:00
Stephane Nicoll c74760540d Polish 2022-10-07 11:42:55 +02:00
Stephane Nicoll a16afe8e10 Describe the replacement use case for BeanRegistrationAotProcessor
Closes gh-29126
2022-10-06 16:42:17 +02:00
Juergen Hoeller 6027be5a39 Ignore overridden factory methods for unique candidate resolution
See gh-27920
2022-10-06 15:06:53 +02:00
Stephane Nicoll 0d5c78d992 Polish 2022-10-06 13:33:58 +02:00
Juergen Hoeller b45a48461f Polishing 2022-10-06 12:03:25 +02:00
Juergen Hoeller aedef9321a Merge AOT constructor and factory method resolution into ConstructorResolver
This moves related code into the same class, unifies candidate determination for constructors and factory methods, and gets rid of the package cycle around the hard-coded Autowired annotation check (which is implicitly coming from AutowiredAnnotationBeanPostProcessor via the determineCandidateConstructors SPI now). The API entry point for AOT pre-resolution purposes is in RegisteredBean.

Closes gh-27920
2022-10-06 11:59:11 +02:00
Stephane Nicoll 2f20d6322b Enable cglib proxy for configuration classes if necessary
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

Closes gh-29107
2022-10-04 16:54:44 +02:00
Stephane Nicoll 9820e3341d Fix handling of protected visibility
Previously, InstanceSupplierCodeGenerator used reflection if the target
visibility is either protected or private, and use direct access if the
target visibility is public or package private.

The previous arrangement already assumed that the code is generateed in
the same package as the target type. This means that protected can be
used as well so this commit only use reflection if the target visibility
is private.

Closes gh-29253
2022-10-04 16:49:13 +02:00
Stephane Nicoll 3b2b36d0b8 Allow AccessControl to determine visibility from a given type
This commit adapts AccessVisibility so that it can determine if the
member or type signature is accessible from a given package. This lets
implementers figure out if reflection is necessary without assuming that
package private visibility is OK.

Closes gh-29245
2022-10-03 17:56:19 +02:00
Brian Clozel 054579a892 Temporarily revert gh-29246
This new hint contribution triggers a GraalVM bug and breaks native
compilation for several samples, we need to temporarily revert this
change until a fix is available in GraalVM.

See gh-29246
2022-10-03 14:14:57 +02:00
Brian Clozel ff9792bae0 Polish
See gh-29246
2022-10-03 14:14:01 +02:00
Brian Clozel 332961f833 Contribute introspection hints on registered beans
As a follow up of #29205, we now need to contribute an "introspection on
declared method" reflection hint for all registered beans.

Closes gh-29246
2022-10-03 11:31:24 +02:00
Stephane Nicoll 0b5c3ec267 Polish javadoc 2022-10-03 10:05:27 +02:00