Repository navigation
Merge 8.0.x into 8.1.x - #16728
Merge 8.0.x into 8.1.x#16728
Conversation
…data Groovy 5 resolves a String subscript on a Map as property access: at runtime getAt(Object, String) and putAt(Object, String, Object) win over the Map overloads, and the static compiler binds a String-keyed read the same way. Every Groovy object has the `properties` and `metaClass` properties, so for any Map, a LinkedHashMap included, `map['properties']` now returns the meta-properties of the map object and `map['properties'] = value` throws ReadOnlyPropertyException. Under @CompileStatic the assignment is still dispatched at runtime by the class of the key, so a statically compiled `map[key] = value` fails the same way for a key named `properties`. GORM for MongoDB decoded Map properties, embedded maps and nested documents with that subscript, so a document holding a GeoJSON Feature, whose `properties` member is part of the format, could not be loaded, and the BsonDocument converter read a nested key such as `firstKey` as a BsonDocument accessor. The data binders built the bound value of a Map property with the same subscript, so binding such a map, or an indexed key such as `attributes[properties]`, recorded a binding error instead of the entry. Use Map.get and Map.put at every site where the key comes from a document or from the binding source: the BsonDocument converter and the MapCodec in CodecExtensions, EmbeddedCollectionDecoder, GrailsWebDataBinder, SimpleDataBinder and AbstractStructuredBindingEditor. A loaded Map property comes back as a DirtyCheckingMap, whose own accessors (target, parent, property, originalSize, assigned) shadow entries of those names through the wrapper although the plain map it wraps exposes them. The wrapper now resolves exactly those five names to the entry in getProperty and setProperty, writing through put so the owner is marked dirty, and leaves every other name to the wrapped map's behaviour. That restores the Grails 7 behaviour for dotted and subscript access in dynamic and statically compiled code alike, except dotted access from statically compiled code, which binds to the accessor at compile time as it always has. Removing the accessors instead, as dc214d9 did for params, would rename getOriginalSize() and isAssigned() on the DirtyCheckableCollection interface, an SPI change this patch line should not make. Upgrade note 28.4, and notes in the data binding and GORM for MongoDB guides, say that application code reads such an entry with get(). Fixes apache#16675
The openapi feature adds springdoc-openapi-starter-webmvc-ui, which brings in the org.webjars:swagger-ui webjar. The asset-pipeline Gradle plugin picks up every webjar on the runtime classpath, and Closure Compiler cannot parse the Swagger UI bundles, so assetCompile (and with it bootWar/bootJar) fails in a freshly generated web application. springdoc serves Swagger UI straight from the webjar, so the asset pipeline has no use for it. Exclude it when the openapi feature is selected.
…PI guide An application that adds springdoc-openapi-starter-webmvc-ui by hand and uses the asset pipeline runs into the same assetCompile failure as one generated with the openapi feature did.
…ies-named-like-properties
The upgrade note described the dirty-checking wrapper as what every loaded GORM Map property comes back as. That is true of GORM for MongoDB only. With GORM for Hibernate a loaded Map property is Hibernate's PersistentMap, whose own accessors (key, value, owner, role, size, session, dirty, ...) hide entries of those names on Groovy 5 and are not redirected, so the note now says so and points at get. The metaClass sentence presented the subscript write as a Groovy 5 change. On Groovy 4 the write already set the metaclass of the map and threw GroovyCastException for any other value; only the read changed. The MongoDB spec now asserts that the loaded map is a DirtyCheckingMap before it reads the entries named like the wrapper's accessors, so the block keeps exercising the getProperty/setProperty override rather than passing against a plain map.
An application running on generated artifacts has the annotation processors registered again, for beans built by a supplier and declared as an interface. Those processors also injected every bean the generated code had already injected, so a side-effecting @Autowired method ran twice: every executor's metrics were registered a second time on a JVM running with -Dspring.aot.enabled=true. The definitions the generated code contributed are now recorded as the context is initialized, before any plugin declares a bean, and the processors registered again leave them alone. They are also declared with suppliers, so creating them needs no reflection. (cherry picked from commit 8bfca2b)
The generated code injects a bean only through the annotated members of the type its definition declares. A factory method declaring an interface, as the link generator's does, leaves every annotated member of the class it returns to the annotation processors Grails registers again. Skipping every generated bean left the link generator without its URL mappings, so the AOT example application failed to render a link. The processors now leave a generated bean alone only when it is of exactly the type its definition declares, or the subclass Spring generates for a configuration class. A side-effecting @Autowired method on such a bean still runs once. (cherry picked from commit f2a1277)
They were written for 9.0 and are backported here.
Moves the build from Gradle 9.8.1 to 9.8.2, the second 9.8 patch release. It fixes a false "graph wasn't stable enough" warning when versions are aligned with a virtual platform (gradle/gradle#39454). `gradle -p gradle-bootstrap` on 9.8.2 changes only the distributionUrl of the root, grails-gradle, grails-forge and end-to-end wrappers. Gradle publishes the same wrapper jar for 9.8.2 as for 9.8.1 (sha256 3b8a2577...), so no jar changes, and `gradlew` and `gradlew.bat` are unchanged. build-logic, the grails-profiles skeletons and the grails-shell-cli gradle-sample fixture, which bootstrap does not reach, get the same distributionUrl. `end-to-end/legacy-g7-command-plugin` stays on 8.14.6, still the latest 8.14 release. `.sdkmanrc`, `gradleToolingApiVersion`, Forge's gradleWrapperProperties template and the gradle-developer and grails-8-upgrade skills move to 9.8.2 as well. The Wrapper task rewrites the properties files from scratch, so the "keep this synced" comments were restored. Release notes: https://docs.gradle.org/9.8.2/release-notes.html
…-named-like-properties Read and write Map entries through the Map API where the key is user data
8.0.0 shipped the openapi feature without the exclude, so an application generated with it fails assetCompile and needs the line added; only applications generated from 8.0.1 have it already.
OpenApiSpec checks that the template prints the exclude, but apache#16707 is about a generated application whose assetCompile fails. Generate a WEB application with openapi and run assetCompile on it.
Upgrade 8.x+ to Gradle 9.8.2
…-ui-asset-compile Keep the Swagger UI webjar out of the asset pipeline in generated apps
GeneratedArtifactsCommonAnnotationBeanPostProcessor stands down in postProcessBeforeDestruction for a bean the generated code created, so the destruction method that code recorded on the definition runs once, called by the container. Nothing exercised that. The fixture now has a @PreDestroy method, which the generated definition records as the generated code does, and a @resource setter, so the common processor's injection is covered as well as the autowired one's. Without the override the destruction method runs twice.
The generated code injects a bean through the annotated members of the type its definition declares. For a factory method declaring a superclass of the class it returns, the processors registered again for generated artifacts then injected the whole class, so the superclass's @Autowired and @resource members ran twice, and so did an @Autowired override of one, which the generated code had already called. Before processing such a bean, the processors now mark those members on its definition as configured from outside, the mechanism Spring uses to keep two processors from injecting one member, and inject only what the subclass adds. Spring's own processor, as the code was generated with, finds the members on the declared type, and the overrides in the bean's class are marked with them. A factory method declaring an interface has no members to mark, so its bean is processed fully, as before. Lifecycle methods are unchanged: the processor calls them all and marks them, so the container skips the ones the generated code recorded.
Spring Boot does not run the generated initializer before every other: it adds it ahead of the application's initializers and sorts them stably, so an initializer with an order runs before it. Recording is correct as long as none of those registers a bean definition, which holds for Spring Boot's own. Say that rather than the stronger claim.
The guide listed the autowired and common annotation processors among the infrastructure an AOT-processed application no longer has. Grails has registered them again since b1611e3, for the annotated members the generated code cannot see: those of a bean a plugin registers at runtime, and those of a bean declared as an interface and built by a supplier. They now leave the members the generated code injected to that code.
A subclass that overrides a generic superclass's annotated setter with the actual type also gets a bridge taking the erased one. The generated code calls the setter through that bridge, and ClassUtils resolves the superclass method to the bridge too, so the bridge was marked. Spring's autowiring metadata skips bridges and keeps the override, which was then injected a second time. BridgeMethodResolver resolves to the method the bridge leads to, which is the member the processor holds.
The definitions the generated code contributed were taken from a snapshot of the bean factory as the context was initialized, and a bean was left alone when its definition was in the snapshot and its class was the type the definition declared. That was wrong three ways: - The snapshot held every definition registered by then, so a bean an initializer ordered ahead of the generated one declared was taken for a generated one, and nobody injected or initialized it. - An inner bean is not in the registry, so it was never in the snapshot, and was injected twice. - The decision went by name and type, not by instance. Another instance under a generated bean's name, as configureBean and the Hibernate bean container create, was left uninjected, and initializeBean skipped its @PostConstruct method. The code generated for each definition, an inner bean's included, now marks it as it returns it. GeneratedInjectionBeanRegistrationAotProcessor has it call GeneratedBeanDefinitions.markGenerated, which names the type whose members that code injects and has the instance supplier record, by identity, each instance it creates. The processors read the mark from the merged definition they are given and mark that type's members, and their overrides, as configured from outside. They then process every bean: an instance the generated code created only through what its class adds, and any other instance in full, through a plain processor whose metadata carries no marks. Lifecycle methods are no longer skipped. The common processor calls the annotated ones for every instance, as on a context without generated code, and the names the generated code recorded for them are taken off its definitions when the processors are registered. Left on, they made configureBean call them twice, since it works on a copy of the definition that keeps the recorded names but not what the processor called. The snapshot, and recording it in GrailsPluginLifecycleInitializer, are gone. GeneratedArtifactsInjectionSpec generates, compiles and runs the code for each case and counts every call; the cases that the snapshot, the name check and the inner bean got wrong fail without this change.
Another instance of a generated bean, one handed to configureBean, is injected in full by Spring's own processors, but each of the two did so on its own. Spring runs the common processor first on a bean's definition, and the autowired processor then leaves to it a member the common one registered there. Without a shared definition, a field or method annotated with both @resource(name = ...) and @Autowired was injected twice, so autowiring replaced the named resource with the primary bean, and a method annotated so ran twice. The autowired processor now has Spring's common processor mark its members on a definition for the instance first, and processes that definition itself before injecting, as Spring would. The regression configures such an instance and checks it against a bean declared any other way: the named resource, and the method called once.
The autowired processor prepared the definition for another instance of a generated bean under the instance's user class, but the injection that follows looks the metadata up under the instance's class. For a CGLIB subclass handed to configureBean, the two differ, so the metadata was rebuilt without the members the common processor had taken, and a member annotated with both @resource(name = ...) and @Autowired was injected twice again. The definition is now prepared under the instance's class. The regression configures a CGLIB-enhanced instance as well as a plain one.
Inside Tenants.withoutId, withTenant(tenantId).get(id) and the other lookups by id through withTenant found an instance of any tenant on GORM for MongoDB and GORM's in-memory datastore, as getAll did on GORM for Neo4j, while a query through withTenant(tenantId) there is restricted to that tenant. Whether a lookup by id goes through a query is now decided inside the session callback, for the session's datastore, as the multi-tenant event listener decides it, so the tenant that withTenant binds for the callback applies. getAll with an iterable of ids passes them to getAll with an array of ids again, as on 7.x, so that a subclass that overrides that, such as GORM for Hibernate's static API, handles both. The GORM for Neo4j guide now says that lookups by id are restricted to the current tenant. Upgrade note 88 no longer says that inside withoutId a lookup by id is not restricted to a tenant on GORM for Neo4j, where get there finds only the instances of the tenant default, as its queries do.
…ant-8.0.x Restrict lookups by id through withTenant inside withoutId
…injected-once-8.0.x 8.0 (fix): Inject the beans generated ahead of time only once
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 8.1.x #16728 +/- ##
==================================================
+ Coverage 63.3076% 63.3231% +0.0155%
- Complexity 28418 28459 +41
==================================================
Files 2307 2311 +4
Lines 113443 113600 +157
Branches 20646 20675 +29
==================================================
+ Hits 71818 71935 +117
- Misses 32213 32242 +29
- Partials 9412 9423 +11
🚀 New features to boost your workflow:
|
🚨 TestLens detected 238 failed tests 🚨Test SummaryTip Inspect all details with the TestLens CLI: Groovy Snapshot Canary Build / Build Grails (shard 0) > :grails-test-examples-mongodb-hibernate5:test
Groovy Snapshot Canary Build / Build Grails (shard 1) > :grails-data-mongodb-core:test (first 40 of 225)
Groovy Snapshot Canary Build / Build Grails (shard 1) > :grails-test-examples-mongodb-test-data-service:integrationTest
Groovy Snapshot Canary Build / Build Grails (shard 2) > :grails-data-mongodb-spring-boot:test
Groovy Snapshot Canary Build / Build Grails (shard 2) > :grails-test-examples-mongodb-base:test
🏷️ Commit: 8910a5c Test Failures (first 10 of 235)BookFongoSpec (:grails-test-examples-mongodb-hibernate5:test in Groovy Snapshot Canary Build / Build Grails (shard 0))AggregateMethodSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))AssignedIdentifierSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))AttachMethodSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))AutowireServicesSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))BasicArraySpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))BasicCollectionTypeSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))BasicCollectionsSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))BatchUpdateDeleteSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))BeforeInsertUpdateSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1))Rerun Controls (first 20 of 238)Note Checks are currently running using the configuration below. Select tests to mute in this pull request: 🔲 AggregateMethodSpec Reuse successful test results: 🔲 ♻️ Only rerun the tests that failed or were muted before Click the checkbox to trigger a rerun: 🔲 Rerun jobs Learn more about TestLens at testlens.app/docs. |
Merges
8.0.xinto8.1.x, which brings #16694, #16708, #16709, #16710 and #16727 to this line.One conflict: #16708 added the
webjars/swagger-ui/**asset exclude tobuildGradle.rocker.raw, which 8.1.x has replaced withbuildGradle.gsp. The exclude is ported to the GSP template under the sameopenapicondition, and the Rocker file stays deleted.gradle.propertiestakes Gradle 9.8.2 from #16710 and keeps 8.1.x's comment pointing atgradleWrapperProperties.gsp.