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

Eric Milles commented on GROOVY-8286:
-------------------------------------

As noted, it has been in common use for so long, it would be a massive breaking 
change to alter this.  STC does check most of the access rules but retains an 
exception for field/property of declaring type.

To try this out in the dynamic case, you would need to be sure that the sender 
is supplied for the method call or field or property accesses.  Using the 
sender (the enclosing class or script) the runtime could determine if a method 
or property should be accessible.

> Groovy does not respect package-private modifier of Java class
> --------------------------------------------------------------
>
>                 Key: GROOVY-8286
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8286
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.8
>            Reporter: Angela Guardian
>            Priority: Major
>
> Hi. I'm using Java (1.8) with Groovy (2.4.8) via GMavenPlus (although with 
> the project I'm working on, we actually also programmatically compile Groovy 
> code and add it to the class loader to mix them up). It seems however, in 
> Groovy scripts/classes, package-private methods defined in a Java class can 
> be called.
> For example, I have a Java class {{Person}} in package 
> {{org.example.people}}, defined like so:
> {code:java}
> package org.example.people;
> public class Person {
>     private String name;
>     void setName(String name) {
>         this.name = name;
>     }
>     public String getName() {
>         return this.name;
>     }
> }
> {code}
> And I have a Groovy class {{Main}} in package {{org.example}}:
> {code:java}
> package org.example
> import groovy.transform.CompileStatic
> import org.example.people.Person
> class Main {
>     static void main(String[] args) {
>         Person person = new Person()
>         person.setName('Bob') // Shouldn't be call-able since they belong to 
> different packages.
>         println person.getName() // Prints 'Bob' to the console.
>     }
> }
> {code}
> Is this standard? Using {{\@CompileStatic}}, though, throws an 
> {{IllegalAccessException}}.
>  



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

Reply via email to