Cannot access a public static volatile field

234 views
Skip to first unread message

vemv

unread,
Mar 17, 2013, 12:54:58 AM3/17/13
to clo...@googlegroups.com
The relevant Java code:

// its class extends Thread

// assigned a value in static initializer
public static volatile ClassLoader classLoader = null;


What happens when I try access it from Clojure:

user=> vemv.NGSession/classLoader

IllegalAccessException Class clojure.lang.Reflector can not access a member of class vemv.NGSession with modifiers "public static volatile"  sun.reflect.Reflection.ensureMemberAccess (Reflection.java:95)

Fortunately I could reproduce the issue isolatedly, in the following class which has no dependencies/etc: https://gist.github.com/vemv/5180168

If I try reproduce the issue absolutely from scratch though, it disappears:

package vemv;

public class Foo extends Thread {
    public static volatile ClassLoader classLoader = null;
    static {
        try {
            classLoader = Foo.class.getClassLoader();
        } catch (SecurityException e) {
            throw e;
        }
    }
}

Any ideas? Should I just open a bug report?

vemv

unread,
Mar 17, 2013, 1:02:07 AM3/17/13
to clo...@googlegroups.com
Ahhh I tracked it down - the class was not public. I thought .java files had to define at least (and at most) *one* public class/enum/interface.

How much sense can it make to define a private class in its own file? :(

Marko Topolnik

unread,
Mar 17, 2013, 2:44:54 AM3/17/13
to clo...@googlegroups.com
On Sunday, March 17, 2013 6:02:07 AM UTC+1, vemv wrote:
Ahhh I tracked it down - the class was not public. I thought .java files had to define at least (and at most) *one* public class/enum/interface.

How much sense can it make to define a private class in its own file? :(

It makes perfect sense: complecting access control with file organization is not exactly a plus for a language. The existing restriction of one public class per file is nuisance enough. Many times it forces the unwieldiness of nested classes upon you.

-Marko

Reply all
Reply to author
Forward
0 new messages