[ 
https://issues.apache.org/jira/browse/GROOVY-12040?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King updated GROOVY-12040:
-------------------------------
    Description: 
This broke Grails.

h3. Summary

{{@groovy.transform.builder.Builder}} was {{@Retention(RUNTIME)}} through 
Groovy 4.0.x. In Groovy 5.0.0 it was changed to {{@Retention(SOURCE)}} in 
[GROOVY-10855|https://issues.apache.org/jira/browse/GROOVY-10855] ("normalized 
annotation metadata"). As a result, {{Class.getAnnotation(Builder.class)}} now 
returns {{null}} at runtime, breaking frameworks that reflect on the annotation 
to detect builder-shaped classes (e.g. Grails 
{{ConfigurationBuilder.buildRecurse}} -- see 
[apache/grails-core#15557|https://github.com/apache/grails-core/pull/15557] row 
4).

GROOVY-10855 was initially about the annotation collectors but we bundled in 
some more AST transform annotations that we weren't aware anyone was using at 
runtime. Builder ended up being a case that was being used.

h3. Reproducer

{code:groovy}
import groovy.transform.builder.Builder
import groovy.transform.builder.SimpleStrategy

@Builder(builderStrategy = SimpleStrategy, prefix = '')
class ConnectionSettings { String host = 'localhost' }

Builder ann = ConnectionSettings.getAnnotation(Builder)
assert ann != null && ann.builderStrategy() == SimpleStrategy
{code}

|| Version || {{getAnnotation(Builder)}} ||
| 3.0.x | non-null (RUNTIME) |
| 4.0.x | non-null (RUNTIME) |
| 5.0.x / 6.0.0-alpha-1 | *null* (SOURCE) |

h3. Root cause

Commit {{3311ee95f5}} flipped {{Builder.java}} from {{RUNTIME}} to {{SOURCE}}. 
GROOVY-10855's stated scope was only the collector/meta-annotations 
({{@Canonical}}, {{@CompileDynamic}}, {{@Immutable}}, {{@RecordType}}) -- the 
change to {{@Builder}} (and a number of other user-facing class annotations) 
was scope-creep, undocumented in release notes, and not covered by tests.

h3. Proposed fix

Revert just {{@Builder}}'s retention to {{RUNTIME}}.

  was:
This broke Grails.

h3. Summary

{{@groovy.transform.builder.Builder}} was {{@Retention(RUNTIME)}} through 
Groovy 4.0.x. In Groovy 5.0.0 it was changed to {{@Retention(SOURCE)}} by 
[GROOVY-10855|https://issues.apache.org/jira/browse/GROOVY-10855] ("normalized 
annotation metadata"). As a result, {{Class.getAnnotation(Builder.class)}} now 
returns {{null}} at runtime, breaking frameworks that reflect on the annotation 
to detect builder-shaped classes (e.g. Grails 
{{ConfigurationBuilder.buildRecurse}} -- see 
[apache/grails-core#15557|https://github.com/apache/grails-core/pull/15557] row 
4).

h3. Reproducer

{code:groovy}
import groovy.transform.builder.Builder
import groovy.transform.builder.SimpleStrategy

@Builder(builderStrategy = SimpleStrategy, prefix = '')
class ConnectionSettings { String host = 'localhost' }

Builder ann = ConnectionSettings.getAnnotation(Builder)
assert ann != null && ann.builderStrategy() == SimpleStrategy
{code}

|| Version || {{getAnnotation(Builder)}} ||
| 3.0.x | non-null (RUNTIME) |
| 4.0.x | non-null (RUNTIME) |
| 5.0.x / 6.0.0-alpha-1 | *null* (SOURCE) |

h3. Root cause

Commit {{3311ee95f5}} flipped {{Builder.java}} from {{RUNTIME}} to {{SOURCE}}. 
GROOVY-10855's stated scope was only the collector/meta-annotations 
({{@Canonical}}, {{@CompileDynamic}}, {{@Immutable}}, {{@RecordType}}) -- the 
change to {{@Builder}} (and a number of other user-facing class annotations) 
was scope-creep, undocumented in release notes, and not covered by tests.

h3. Proposed fix

Revert just {{@Builder}}'s retention to {{RUNTIME}}. Audit other class-facing 
transforms swept by the same commit ({{@ToString}}, {{@AutoClone}}, 
{{@Sortable}}, {{@EqualsAndHashCode}}, {{@TupleConstructor}}, 
{{@MapConstructor}}, {{@Memoized}}, {{@AutoImplement}}) for the same regression 
risk.


> restore @Builder retention to RUNTIME in 5.0.x
> ----------------------------------------------
>
>                 Key: GROOVY-12040
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12040
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> This broke Grails.
> h3. Summary
> {{@groovy.transform.builder.Builder}} was {{@Retention(RUNTIME)}} through 
> Groovy 4.0.x. In Groovy 5.0.0 it was changed to {{@Retention(SOURCE)}} in 
> [GROOVY-10855|https://issues.apache.org/jira/browse/GROOVY-10855] 
> ("normalized annotation metadata"). As a result, 
> {{Class.getAnnotation(Builder.class)}} now returns {{null}} at runtime, 
> breaking frameworks that reflect on the annotation to detect builder-shaped 
> classes (e.g. Grails {{ConfigurationBuilder.buildRecurse}} -- see 
> [apache/grails-core#15557|https://github.com/apache/grails-core/pull/15557] 
> row 4).
> GROOVY-10855 was initially about the annotation collectors but we bundled in 
> some more AST transform annotations that we weren't aware anyone was using at 
> runtime. Builder ended up being a case that was being used.
> h3. Reproducer
> {code:groovy}
> import groovy.transform.builder.Builder
> import groovy.transform.builder.SimpleStrategy
> @Builder(builderStrategy = SimpleStrategy, prefix = '')
> class ConnectionSettings { String host = 'localhost' }
> Builder ann = ConnectionSettings.getAnnotation(Builder)
> assert ann != null && ann.builderStrategy() == SimpleStrategy
> {code}
> || Version || {{getAnnotation(Builder)}} ||
> | 3.0.x | non-null (RUNTIME) |
> | 4.0.x | non-null (RUNTIME) |
> | 5.0.x / 6.0.0-alpha-1 | *null* (SOURCE) |
> h3. Root cause
> Commit {{3311ee95f5}} flipped {{Builder.java}} from {{RUNTIME}} to 
> {{SOURCE}}. GROOVY-10855's stated scope was only the 
> collector/meta-annotations ({{@Canonical}}, {{@CompileDynamic}}, 
> {{@Immutable}}, {{@RecordType}}) -- the change to {{@Builder}} (and a number 
> of other user-facing class annotations) was scope-creep, undocumented in 
> release notes, and not covered by tests.
> h3. Proposed fix
> Revert just {{@Builder}}'s retention to {{RUNTIME}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to