[jira] [Updated] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread Eric Milles (Jira)


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

Eric Milles updated GROOVY-11508:
-
Description: 
When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
prevents us from updating to Groovy 4 for the 
[grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
project.  Groovy-5106 does not take into account relationships between generic 
types and groovy does not support inheritance in generic types on traits so we 
have no workable solution for using Groovy 4.

 

For example, the following is not possible in Groovy 4:
{code:java}
class Parent extends GormEntity {

}

class Child extends GormEntity {

} 

class GormEntity { // ? extends GormEntity is not allowed

}{code}
 

We have documented the impacts of this issue on the grails-data-mapping project 
here:  [https://github.com/grails/grails-data-mapping/issues/1811]   We have 
discovered that the original change could be reverted and continue to work with 
the latest Java & Groovy. 

 

For Grails Data Mapping (GORM), there is support for inheritance between a 
Parent & Child domain object.  This is often implemented like this:
{code:java}
class Parent extends GormEntity {

}

class Child extends GormEntity {

}

trait GormEntity { // Simplified for this ticket
    static D get(Serializable id)
   
static List getAll()
}
 {code}
This allows someone to do the following in code:
{code:java}
Parent.get(1L) // Will find either a Child or Parent
Child.get(1L) // Will find only child types{code}
 

Since Groovy-5106 does not take into account inheritance, can this change be 
reverted or changed to a warning until inheritance is taken into account?

  was:
When updating Grails from Groovy 3.x to 4.x we discovered that Groovy-5106 
prevents us from updating to Groovy 4 for the 
[grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
project.  Groovy-5106 does not take into account relationships between generic 
types and groovy does not support inheritance in generic types on traits so we 
have no workable solution for using Groovy 4.

 

For example, the following is not possible in Groovy 4:
{code:java}
class Parent extends GormEntity {

}

class Child extends GormEntity {

} 

class GormEntity { // ? extends GormEntity is not allowed

}{code}
 

We have documented the impacts of this issue on the grails-data-mapping project 
here:  [https://github.com/grails/grails-data-mapping/issues/1811]   We have 
discovered that the original change could be reverted and continue to work with 
the latest Java & Groovy. 

 

For Grails Data Mapping (GORM), there is support for inheritance between a 
Parent & Child domain object.  This is often implemented like this:
{code:java}
class Parent extends GormEntity {

}

class Child extends GormEntity {

}

trait GormEntity { // Simplified for this ticket
    static D get(Serializable id)
   
static List getAll()
}
 {code}
This allows someone to do the following in code:
{code:java}
Parent.get(1L) // Will find either a Child or Parent
Child.get(1L) // Will find only child types{code}
 

Since Groovy-5106 does not take into account inheritance, can this change be 
reverted or changed to a warning until inheritance is taken into account?


> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEnt

[jira] [Commented] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892642#comment-17892642
 ] 

Eric Milles commented on GROOVY-11508:
--

The examples do not indicate any relationship between Parent and Child

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Comment Edited] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread James Daugherty (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892651#comment-17892651
 ] 

James Daugherty edited comment on GROOVY-11508 at 10/25/24 2:29 AM:


As for static example, the class file that's generated in 3.x shows:

 

Child Class:
{code:java}
public class Child extends Parent implements GormEntity {
// Only including the getAll method() for discussion purposes
    @TraitBridge(
traitClass = GormEntity.class,
desc = "()Ljava/util/List;"
)  
public static List getAll() {
CallSite[] var0 = $getCallSiteArray();
return 
(List)ScriptBytecodeAdapter.castToType(var0[4].call(GormEntity$Trait$Helper.class,
 Child.class), List.class);
}
} {code}
 

Parent Class
{code:java}
public class Parent implements GormEntity, GroovyObject {
     // Only including the getAll method() for discussion purposes
     @TraitBridge(
traitClass = GormEntity.class,
desc = "()Ljava/util/List;" 
)
public static List getAll() {
CallSite[] var0 = $getCallSiteArray();
return 
(List)ScriptBytecodeAdapter.castToType(var0[4].call(GormEntity$Trait$Helper.class,
 Parent.class), List.class);
}
} {code}
 

Groovy 3 chose the method from the last declared trait per the docs 
([https://docs.groovy-lang.org/latest/html/documentation#_default_conflict_resolution]).
   This resolution logic seems to apply regardless if a method is static.  The 
data mapping project in Grails took advantage of this so that a child would 
invoke the child specific code, while a parent would invoke the parent one.


was (Author: jdaugherty):
As for static example, the class file that's generated in 3.x shows:

 

Child Class:
{code:java}
public class Child extends Parent implements GormEntity {
// Only including the getAll method() for discussion purposes
    @TraitBridge(
traitClass = GormEntity.class,
desc = "()Ljava/util/List;"
)  
public static List getAll() {
CallSite[] var0 = $getCallSiteArray();
return 
(List)ScriptBytecodeAdapter.castToType(var0[4].call(GormEntity$Trait$Helper.class,
 Child.class), List.class);
}
} {code}
 

Parent Class
{code:java}
public class Parent implements GormEntity, GroovyObject {
     // Only including the getAll method() for discussion purposes
     @TraitBridge(
traitClass = GormEntity.class,
desc = "()Ljava/util/List;" 
)
public static List getAll() {
CallSite[] var0 = $getCallSiteArray();
return 
(List)ScriptBytecodeAdapter.castToType(var0[4].call(GormEntity$Trait$Helper.class,
 Parent.class), List.class);
}
} {code}
 

I would have expected this behavior since the trait resolution in the docs 
([https://docs.groovy-lang.org/latest/html/documentation#_default_conflict_resolution])
 says the last declared trait chooses the method that's copied to the 
implementing class.  The data mapping project in Grails took advantage of this 
so that a child would invoke the child specific code, while a parent would 
invoke the parent one.

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> P

[jira] [Commented] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread James Daugherty (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892649#comment-17892649
 ] 

James Daugherty commented on GROOVY-11508:
--

As for static, the same issue will exist with non-static methods:

 
{code:java}
import groovy.transform.CompileStatic
import java.util.Map
import java.util.List

trait GormEntity {
D refresh() {
this
}
}

class Parent implements GormEntity {
String name
}

class Child extends Parent implements GormEntity {
String otherField
}

Parent p = new Parent()
Child c = new Child()

if(p.refresh() != p) {
System.out.println("Unexpected")
}

if(c.refresh() != c) {
System.out.println("Unexpected")
} {code}

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Commented] (GROOVY-11459) weak hashing algorithm (使用弱哈希算法)

2024-10-24 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11459?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892529#comment-17892529
 ] 

ASF GitHub Bot commented on GROOVY-11459:
-

GianniGiglio commented on PR #2112:
URL: https://github.com/apache/groovy/pull/2112#issuecomment-2435613155

   Hi are there any plans to backport this to groovy 4 release?




> weak hashing algorithm (使用弱哈希算法)
> 
>
> Key: GROOVY-11459
> URL: https://issues.apache.org/jira/browse/GROOVY-11459
> Project: Groovy
>  Issue Type: Bug
>Affects Versions: 4.0.22
>Reporter: wellchang
>Assignee: Paul King
>Priority: Major
> Fix For: 4.x
>
>
> 通过iast扫描发现groovy中使用了md5来生成缓存键名,路径为groovy.lang.GroovyClassLoader.getSourceCacheKey
> 建议使用常见的安全的哈希算法,如SHA-256,SHA-384,SHA-512等
> Google Translate gives:
> Through iast scanning, it was found that md5 is used in groovy to generate 
> the cache key name, and the path is 
> groovy.lang.GroovyClassLoader.getSourceCacheKey
> It is recommended to use common secure hash algorithms, such as SHA-256, 
> SHA-384, SHA-512, etc.



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


[jira] [Created] (GROOVY-11508) Revert Groovy-5106 or allow it to be a warning only

2024-10-24 Thread James Daugherty (Jira)
James Daugherty created GROOVY-11508:


 Summary: Revert Groovy-5106 or allow it to be a warning only
 Key: GROOVY-11508
 URL: https://issues.apache.org/jira/browse/GROOVY-11508
 Project: Groovy
  Issue Type: Bug
  Components: Compiler
Affects Versions: 4.0.0
Reporter: James Daugherty


When updating Grails from Groovy 3.x to 4.x we discovered that Groovy-5106 
prevents us from updating to Groovy 4 for the grails-data-mapping (GORM) 
project.  Groovy-5106 does not take into relationships between generic types 
and groovy does not support inheritance in generic types on traits so we have 
no workable solution for using Groovy 4. 

 

For example, the following is not possible in Groovy 4:
{code:java}
class Parent extends GormEntity {

}

class Child extends GormEntity {

} 

class GormEntity { // ? extends GormEntity is not allowed

}{code}
 

We have documented this issue on the grails-data-mapping project here:  
[https://github.com/grails/grails-data-mapping/issues/1811]   We have 
discovered that the original change could be reverted and continue to work with 
the latest Java & Groovy. 

 

For Grails Data Mapping (GORM), there is support for inheritance between a 
Parent & Child domain object.  This is often implemented like this:
{code:java}
class Parent extends GormEntity {

}

class Child extends GormEntity {

}

trait GormEntity {
static D get(Serializable id)

// Simplified for this ticket
static List getAll()
}
 {code}
This allows someone to do the following in code:
{code:java}
Parent.get(1L) // Will find either a Child or Parent
Child.get(1L) // Will find only child types{code}
 

Since Groovy-5106 does not take into account inheritance, can this change be 
reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Commented] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892643#comment-17892643
 ] 

Eric Milles commented on GROOVY-11508:
--

Also, type vars do not apply to static members, so I don’t know what this is 
supposed to do. 

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Assigned] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread Eric Milles (Jira)


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

Eric Milles reassigned GROOVY-11508:


Assignee: Eric Milles

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that Groovy-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Updated] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread James Daugherty (Jira)


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

James Daugherty updated GROOVY-11508:
-
Summary: Multiple traits with related generic types cannot be used  (was: 
Revert Groovy-5106 or allow it to be a warning only)

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that Groovy-5106 
> prevents us from updating to Groovy 4 for the grails-data-mapping (GORM) 
> project.  Groovy-5106 does not take into relationships between generic types 
> and groovy does not support inheritance in generic types on traits so we have 
> no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented this issue on the grails-data-mapping project here:  
> [https://github.com/grails/grails-data-mapping/issues/1811]   We have 
> discovered that the original change could be reverted and continue to work 
> with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Commented] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread James Daugherty (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892647#comment-17892647
 ] 

James Daugherty commented on GROOVY-11508:
--

I realized I didn't extend Parent, here's the full example.  This works on 
groovy 3.x, but not on 4.x:

 
{code:java}
import groovy.transform.CompileStatic
import java.util.Map
import java.util.List

class DatastoreHolder {
static Map datastore = [:].withDefault { [] }
}

trait GormEntity {
abstract static String getEntityName()

static List getAll() {
DatastoreHolder.datastore.get(getEntityName())
}
}

class Parent implements GormEntity {
String name

Parent() {
DatastoreHolder.datastore.get("Parent").add(this)
}

static String getEntityName() {
"Parent"
}
}

class Child extends Parent implements GormEntity {
String otherField

Child() {
super()
DatastoreHolder.datastore.get("Child").add(this)
}

static String getEntityName() {
"Child"
}
}

Parent p = new Parent()
Child c = new Child()

boolean expected = true
if( Parent.getAll().size() != 2) {
expected = false
System.out.println("Parent not expected: ${Parent.getAll()}")
}

if(Child.getAll().size() != 1) {
expected = false
System.out.println("Child not expected: ${Child.getAll()[0]} vs ${c}")
}

if(expected) {
System.out.println("Expected")
}{code}

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Commented] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread James Daugherty (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892651#comment-17892651
 ] 

James Daugherty commented on GROOVY-11508:
--

As for static example, the class file that's generated in 3.x shows:

 

Child Class:
{code:java}
public class Child extends Parent implements GormEntity {
// Only including the getAll method() for discussion purposes
    @TraitBridge(
traitClass = GormEntity.class,
desc = "()Ljava/util/List;"
)  
public static List getAll() {
CallSite[] var0 = $getCallSiteArray();
return 
(List)ScriptBytecodeAdapter.castToType(var0[4].call(GormEntity$Trait$Helper.class,
 Child.class), List.class);
}
} {code}
 

Parent Class
{code:java}
public class Parent implements GormEntity, GroovyObject {
     // Only including the getAll method() for discussion purposes
     @TraitBridge(
traitClass = GormEntity.class,
desc = "()Ljava/util/List;" 
)
public static List getAll() {
CallSite[] var0 = $getCallSiteArray();
return 
(List)ScriptBytecodeAdapter.castToType(var0[4].call(GormEntity$Trait$Helper.class,
 Parent.class), List.class);
}
} {code}
 

I would have expected this behavior since the trait resolution in the docs 
([https://docs.groovy-lang.org/latest/html/documentation#_default_conflict_resolution])
 says the last declared trait chooses the method that's copied to the 
implementing class.  The data mapping project in Grails took advantage of this 
so that a child would invoke the child specific code, while a parent would 
invoke the parent one.

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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


[jira] [Commented] (GROOVY-11508) Multiple traits with related generic types cannot be used

2024-10-24 Thread James Daugherty (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892652#comment-17892652
 ] 

James Daugherty commented on GROOVY-11508:
--

 

As for the static method behavior, given this class:
{code:java}
import groovy.transform.CompileStatic
import java.util.Map
import java.util.List

trait GormEntity {
abstract static String getEntityName()

static List getAll() {
[3]
}
}

trait GormEntity2 {
abstract static String getEntityName()

static List getAll() {
[2]
}
}

class Parent implements GormEntity, GormEntity2 {
String name
}

Parent p = new Parent() {code}
Groovy 3 generates this code on the parent class for the getAll() method:
{code:java}
@TraitBridge(
traitClass = GormEntity2.class,
desc = "()Ljava/util/List;"
)
public static List getAll() {
CallSite[] var0 = $getCallSiteArray();
return 
(List)ScriptBytecodeAdapter.castToType(var0[2].call(GormEntity2$Trait$Helper.class,
 Parent.class), List.class);
}{code}
Groovy 4 generates this code on the parent class for the getAll() method:
{code:java}
@TraitBridge(
traitClass = GormEntity2.class,
desc = "()Ljava/util/List;"
)
public static List getAll() {
return 
((Class)GormEntity2$Trait$Helper.class.invoke(GormEntity2$Trait$Helper.class,
 
Parent.class)).cast(GormEntity2$Trait$Helper.class.invoke(GormEntity2$Trait$Helper.class,
 Parent.class));
} {code}
So it seems that v3 & v4 are consistent with copying the last declared trait's 
static method to the class.

> Multiple traits with related generic types cannot be used
> -
>
> Key: GROOVY-11508
> URL: https://issues.apache.org/jira/browse/GROOVY-11508
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 4.0.0
>Reporter: James Daugherty
>Assignee: Eric Milles
>Priority: Major
>
> When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 
> prevents us from updating to Groovy 4 for the 
> [grails-data-mapping|https://github.com/grails/grails-data-mapping] (GORM) 
> project.  Groovy-5106 does not take into account relationships between 
> generic types and groovy does not support inheritance in generic types on 
> traits so we have no workable solution for using Groovy 4.
>  
> For example, the following is not possible in Groovy 4:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> } 
> class GormEntity { // ? extends GormEntity is not 
> allowed
> }{code}
>  
> We have documented the impacts of this issue on the grails-data-mapping 
> project here:  [https://github.com/grails/grails-data-mapping/issues/1811]   
> We have discovered that the original change could be reverted and continue to 
> work with the latest Java & Groovy. 
>  
> For Grails Data Mapping (GORM), there is support for inheritance between a 
> Parent & Child domain object.  This is often implemented like this:
> {code:java}
> class Parent extends GormEntity {
> }
> class Child extends GormEntity {
> }
> trait GormEntity { // Simplified for this ticket
>     static D get(Serializable id)
>
> static List getAll()
> }
>  {code}
> This allows someone to do the following in code:
> {code:java}
> Parent.get(1L) // Will find either a Child or Parent
> Child.get(1L) // Will find only child types{code}
>  
> Since Groovy-5106 does not take into account inheritance, can this change be 
> reverted or changed to a warning until inheritance is taken into account?



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