You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Angela Vibar Guardian (JIRA)" <ji...@apache.org> on 2017/08/11 07:47:00 UTC
[jira] [Created] (GROOVY-8286) Groovy does not respect
package-private modifier of Java class
Angela Vibar Guardian created GROOVY-8286:
---------------------------------------------
Summary: 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 Vibar Guardian
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
(v6.4.14#64029)