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

ASF GitHub Bot commented on GROOVY-12024:
-----------------------------------------

sonarqubecloud[bot] commented on PR #2580:
URL: https://github.com/apache/groovy/pull/2580#issuecomment-4587453544

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_groovy&pullRequest=2580) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [1 New 
issue](https://sonarcloud.io/project/issues?id=apache_groovy&pullRequest=2580&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_groovy&pullRequest=2580&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_groovy&pullRequest=2580&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [100.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_groovy&pullRequest=2580&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_groovy&pullRequest=2580&metric=new_duplicated_lines_density&view=list)
  
     
   <!

> Subscript operator for Map has unexpected behavior when key is 'properties'
> ---------------------------------------------------------------------------
>
>                 Key: GROOVY-12024
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12024
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: David Costanzo
>            Assignee: Eric Milles
>            Priority: Minor
>
> The subscript operator has strange behavior for Map when the key is 
> 'properties'.  Instead of accessing the value associated with that key, it 
> accesses a read-only Map object.
> This behavior changed between Groovy 3 and Groovy 5.  My expectation is that 
> the subscript operator can access values for a key named 'properties', as it 
> did in Groovy 3.
> *Steps to Reproduce:*
> In groovysh 5, the subscript operator references the system-provided, 
> read-only map.
>  
> {code:java}
> groovy> map = ['properties': 1]
> groovy> map['properties']
> [:]
> groovy> map['properties'] = 2
> ReadOnlyPropertyException: Cannot set read-only property: properties for 
> class: java.util.LinkedHashMap{code}
>  
> In groovysh 3, the subscript operator references keys of the user-created map.
>  
> {code:java}
> groovy:000>  map = ['properties': 1]
> ===> [properties:1]
> groovy:000> map['properties']
> ===> 1
> groovy:000> map['properties'] = 2
> ===> 2{code}
>  
> I don't know if this is intentional, but I couldn't find a reference to in 
> the documentation.  On 
> [https://docs.groovy-lang.org/latest/html/documentation/#subscript-operator] 
> it says that the subscript operators is a shorthand for getAt() and setAt().  
> On 
> [https://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/Map.html#getAt(java.lang.Object)]
>  it does not mention that "properties" can't be used as a key.
> In my view, this is either a code bug (an internal implementation detail is 
> being exposed beyond it's intended scope) or a doc bug (the subscript 
> operator or Map.getAt() should mention the reserved system key named 
> "properties").
> *Impact:*
> This creates the potential for hidden bugs.  For example, I have a script 
> that manages some metadata for internal libraries using a map keyed by the 
> library name.  The script  appears to work correctly, but then I add a 
> library named "properties" and the script fails to work.  (This is not 
> theoretical, this is what actually happened to me).
>  



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

Reply via email to