beanshell2 icon indicating copy to clipboard operation
beanshell2 copied to clipboard

Class generation requires reflective Accessibility

Open GoogleCodeExporter opened this issue 10 years ago • 1 comments

When trying to create an anonymous class from an Applet (or other
environments with restricted policies) you get an exception.

You can reproduce the problem evaluating this code from an applet:

Runnable r = new Runnable(){ 
  public void run() {}
};

In ClassGenerator.java, line 78, I found this comment:

// Scripting classes currently requires accessibility
// This can be eliminated with a bit more work.

I think it's a bit optimistic, but I want to believe :-)

Can you tell me if it is planned to be fixed? I know that working with
applets in 2009 sounds a bit strange, but believe me, it's for a good cause ;-)

regards

Luigi

Original issue reported on code.google.com by [email protected] on 10 Aug 2009 at 7:57

GoogleCodeExporter avatar Apr 22 '15 19:04 GoogleCodeExporter

Hi,

I managed to make it work in a signed applet. 
The modifications I made consist essentially in three points:
- override the getPermissions(CodeSource) method in BshClassLoader
- catch an exception when calling getDeclaredFields/Methods/Constructors and 
call
getFields/Methods/Constructors instead
- avoid calling field.setAccessible(), or at least catch an exception

Maybe I broke something with this (I should run some tests to verify it), but it
seems to work...

You can find attached a diff file with my (actually rough) modifications.

regards 

Luigi

ps. the project I'm working on is this: 
http://sourceforge.net/projects/javaclientpages/

Original comment by [email protected] on 21 Aug 2009 at 7:57

Attachments:

GoogleCodeExporter avatar Apr 22 '15 19:04 GoogleCodeExporter