M201370367 / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 1 forks source link

Class generation requires reflective Accessibility #31

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 luigi.de...@gmail.com on 10 Aug 2009 at 7:57

GoogleCodeExporter commented 9 years ago
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 luigi.de...@gmail.com on 21 Aug 2009 at 7:57

Attachments: