JDK-4710855 : IllegalAccessException calling public method of object whose class is anonymous.
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-07-03
  • Updated: 2002-08-09
  • Resolved: 2002-08-09
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 07/03/2002


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
Microsoft Internet Explorer [Version 5.00.3315.1000]

A DESCRIPTION OF THE PROBLEM :
If a web page contains javascript that attempts to call a
public method of an object that is an instance of an
anonymous class, then an IllegalAccessException is
generated.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Copy the attached files to a single folder.

2. Build the sample applet, consisting of the single source
file "MyApplet.java".

3. Open the test page "Test.htm" in Internet Explorer.

4. Click on the "Try it" link. This calls a javascript
function that attempts to invoke a public method on an
object that is an instance of an anonymous class.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: The method should succeed, and an alert should
display the message: "I'm anonymous!".

Actual: The method fails with an IllegalAccessException.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
A Runtime Error has occurred.
Do you wish to debug?

Line: 10
Error: java.lang.IllegalAccessException: Class
sun.beans.ole.JavaObjectInterface can not access a member of class MyApplet$1
with modifiers "public"

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
---------------------------------------------------------------
MyApplet.java
---------------------------------------------------------------

import java.applet.*;

public class MyApplet extends Applet
{
    public Object getObject()
    {
        return(new Object() {
            public String toString()
            {
                return("I'm anonymous!");
            }
        });
    }
}

---------------------------------------------------------------
Test.htm
---------------------------------------------------------------
<HTML>
<BODY>
<applet codebase="." code="MyApplet.class" height="2" width="2" hspace="0"
vspace="0" style="background-color:#CCCCCC;visibility:hidden" name="A1" id="A1">
</applet>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Test()
{
    var app = document.applets.A1;
    var obj = app.getObject();
    var str = obj.toString();
    alert(str);
}
//-->
</SCRIPT>
<table cellspacing=4 cellpadding=4 border=0>
<tr>
    <td><A href="javascript:Test()">Try it.</A></td>
</tr>
</table>
</BODY>
</HTML>


---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Don't use an anonymous class.
(Review ID: 153903) 
======================================================================

Comments
EVALUATION This is a duplicate of #4071957 ###@###.### 2002-08-09
09-08-2002