groovy

No access protection for private static fields

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1-beta-2
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows XP, Java 1.5, also Ubuntu 7.04 "Feisty Fawn" (JDK 1.6.0) + Groovy Subversion r6911
  • Number of attachments :
    0

Description

Groovysh lets you set & read private member fields, as long as they're static:

groovy> class C { private static x }
groovy> C.x = new Integer(10)
groovy> println C.x
groovy> go
10

Note that it doesn't let you access regular private fields:

groovy> class B { private x }
groovy> b = new B()
groovy> b.x = new Integer(10)
groovy> go
Caught: groovy.lang.IllegalPropertyAccessException: Can not access the
private field x in class B

Issue Links

Activity

Hide
Kim, Pilho added a comment -

With jsr-03, IllegalPropertyAccessException has been thrown.
But with the current jsr-04-SNAPSHOT (CVS HEAD), it looks to work fine.

Lets get Groovy!
================
Version: 1.0-jsr-04-SNAPSHOT JVM: 1.4.2_07-b05
Type 'exit' to terminate the shell
Type 'help' for command help
Type 'go' to execute the statements

groovy> class B { private x }
groovy> b = new B()
groovy> b.x = new Integer(10)
groovy> println b.x
groovy> go
10

Show
Kim, Pilho added a comment - With jsr-03, IllegalPropertyAccessException has been thrown. But with the current jsr-04-SNAPSHOT (CVS HEAD), it looks to work fine. Lets get Groovy! ================ Version: 1.0-jsr-04-SNAPSHOT JVM: 1.4.2_07-b05 Type 'exit' to terminate the shell Type 'help' for command help Type 'go' to execute the statements groovy> class B { private x } groovy> b = new B() groovy> b.x = new Integer(10) groovy> println b.x groovy> go 10
Hide
Thomas Adam added a comment -

there is also not protection for private / protected methods

in jsr-06

Show
Thomas Adam added a comment - there is also not protection for private / protected methods in jsr-06
Hide
blackdrag blackdrag added a comment -

private will have no protection in 1.0. private is not inherited, but you can access it

Show
blackdrag blackdrag added a comment - private will have no protection in 1.0. private is not inherited, but you can access it
Hide
Russel Winder added a comment -

private not being private is a regular theme

Show
Russel Winder added a comment - private not being private is a regular theme

People

Vote (8)
Watch (8)

Dates

  • Created:
    Updated: