JDK-4852768 : Exception when accessing Enumerator object from VBScript (ASP)
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-04-23
  • Updated: 2003-08-19
  • Resolved: 2003-08-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Description

Name: gm110360			Date: 04/23/2003


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

EXTRA RELEVANT SYSTEM CONFIGURATION :
MS Windows Scrip Host version 5.6

A DESCRIPTION OF THE PROBLEM :
A simple test bean returns a Properties object froma amethod. The "getPropertyNames" method returns an Enumerator. Method calls on the numerator throw:

java.lang.IllegalAccessException: Class sun.plugin.com.MethodDispatcher can not access a member of class java.util.Hashtable$Enumerator with modifiers "public"
	at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
	at sun.plugin.com.DispatchImpl.invoke(Unknown Source)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile TestBean.java (below)
Put it in a Jar
Run packager against the jar
Put the jar in j2re1.4.2\axbridge\lib
Put the resultant DLL in j2re1.4.2\axbridge\bin
Register the dll using regsvr32

Create testbean.vbs with the script contents below.
Run in a DOS box using "cscript testbean.vbs"

EXPECTED VERSUS ACTUAL BEHAVIOR :
Output from the script:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. Tous droits r��serv��s.

defaultname
new name
OK to here
End

Output from the script:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. Tous droits r��serv��s.

defaultname
new name
OK to here
C:\Documents and Settings\mbartlet\Mes documents\Scripting\Hello.vbs(10, 2) (nul
l): java.lang.IllegalAccessException: Class sun.plugin.com.MethodDispatcher can
not access a member of class java.util.Hashtable$Enumerator with modifiers "publ
ic"

ERROR MESSAGES/STACK TRACES THAT OCCUR :
In the DOS console:

C:\Documents and Settings\mbartlet\Mes documents\Scripting\Hello.vbs(10, 2) (nul
l): java.lang.IllegalAccessException: Class sun.plugin.com.MethodDispatcher can
not access a member of class java.util.Hashtable$Enumerator with modifiers "publ
ic"

In the Java console:

java.lang.IllegalAccessException: Class sun.plugin.com.MethodDispatcher can not access a member of class java.util.Hashtable$Enumerator with modifiers "public"
	at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
	at sun.plugin.com.DispatchImpl.invoke(Unknown Source)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
The bean code:

import java.util.*;

public class TestBean
{
	public TestBean()
	{
		name = "defaultname";
	}
	
	public String getName()
	{
		return name;
	}
	
	public Properties getSystemEnvironment()
	{
		return System.getProperties();
	}

	public void setName(String newName)
	{
		name = newName;
	}
	
	private String name;
}

The script code (executed using Windows Script Engine):

	set cn = CreateObject("TestBean.Bean")
	oldname = cn.name
	WScript.echo(oldname)
	cn.name = "new name"
	newname = cn.name
	WScript.echo(newname)
	set props = cn.systemEnvironment
	set enumb  = props.propertyNames()
	WScript.echo("OK to here")
	more = enumb.hasMoreElements
	WScript.echo("End")


---------- END SOURCE ----------
(Review ID: 184658) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b16
14-06-2004

SUGGESTED FIX ------- MethodDispatcher.java ------- *** /tmp/dJwaa3J Fri Aug 1 14:16:45 2003 --- MethodDispatcher.java Fri Aug 1 12:48:40 2003 *************** *** 8,13 **** --- 8,16 ---- package sun.plugin.com; import java.lang.reflect.Method; + import java.lang.reflect.Modifier; + import java.security.AccessController; + import java.security.PrivilegedAction; import sun.plugin.util.Trace; /** *************** *** 47,54 **** --- 50,69 ---- Object retObj = null; if(method != null && obj != null) { Trace.msgLiveConnectPrintln("com.method.invoke", new Object[] {method}); + Class theClass = obj.getClass(); Object[] params = TypeConverter.convertObjectArray( method.getParameterTypes(), args); + // check if the class is private and the method is public + if (Modifier.isPrivate(theClass.getModifiers()) && + Modifier.isPublic(method.getModifiers()) ) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + // setAccessible to bypass security check + method.setAccessible(true); + return null; // nothing to return + } + }); + } retObj = Utils.convertReturn( method.getReturnType(), method.invoke(obj, params )); }
11-06-2004

EVALUATION This problem can be demonstrated by the following standalone test program: import java.util.*; import java.lang.reflect.Method; public class TestEnum { public static void main (String[] argv) { Hashtable Htab = new Hashtable(); Enumeration enum = Htab.elements(); try { //Method m = Enumeration.class.getDeclaredMethod("hasMoreElements", new Class[]{}); Method m = enum.getClass().getDeclaredMethod("hasMoreElements", new Class[]{}); System.out.println("method " + m); m.invoke(enum, null); } catch (IllegalAccessException e) { System.out.println("IllegalAccessException " + e); } catch (Exception e) { System.out.println("Exception " + e); } } } Note that the above program runs fine if the method m is obtained by the commented line: Method m = Enumeration.class.getDeclaredMethod("hasMoreElements", new Class[]{}); It is because java.util.Hashtable$Enumerator is a private inner class whereas java.util.Enumeration is a public interface. A potential fix in MethodDispatcher.java is to check for the private class. If the class is private, get the interface and the public method. And use the public method to do the invoke. See suggested fix for source diffs. ###@###.### 2003-04-29 Came up with a slightly different fix. In MethodDispatcher, check for private class and public method. Use setAccessible api to bypass security check. I've updated suggested fix with this new fix. ###@###.### 2003-04-29
29-04-2003