From: <vam...@us...> - 2023-10-14 11:42:04
|
Revision: 25697 http://sourceforge.net/p/jedit/svn/25697 Author: vampire0 Date: 2023-10-14 11:42:01 +0000 (Sat, 14 Oct 2023) Log Message: ----------- Make BeanShell behave consistent and remove the need for reflection when defining classes (#4118) Modified Paths: -------------- jEdit/trunk/doc/CHANGES.txt jEdit/trunk/org/gjt/sp/jedit/bsh/Capabilities.java jEdit/trunk/org/gjt/sp/jedit/bsh/ClassGeneratorImpl.java jEdit/trunk/org/gjt/sp/jedit/bsh/LHS.java jEdit/trunk/org/gjt/sp/jedit/bsh/Reflect.java Removed Paths: ------------- jEdit/trunk/org/gjt/sp/jedit/bsh/reflect/ Modified: jEdit/trunk/doc/CHANGES.txt =================================================================== --- jEdit/trunk/doc/CHANGES.txt 2023-10-13 21:05:09 UTC (rev 25696) +++ jEdit/trunk/doc/CHANGES.txt 2023-10-14 11:42:01 UTC (rev 25697) @@ -9,6 +9,12 @@ {{{ Bug Fixes +- BeanShell snippets and macros now work consistently and not suddenly change + behaviour anymore just because some BeanShell snippet defined a class. + This now disables reflective access to otherwise inaccessible fields through + simple syntax though, that used to work after a snippet with a class + definition was loaded. (#4118 - Björn Kautler) + - Fix the installation of plugins trying to use invalid file names (Björn Kautler) Modified: jEdit/trunk/org/gjt/sp/jedit/bsh/Capabilities.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/bsh/Capabilities.java 2023-10-13 21:05:09 UTC (rev 25696) +++ jEdit/trunk/org/gjt/sp/jedit/bsh/Capabilities.java 2023-10-14 11:42:01 UTC (rev 25697) @@ -7,7 +7,7 @@ * * * The contents of this file are subject to the Sun Public License Version * * 1.0 (the "License"); you may not use this file except in compliance with * - * the License. A copy of the License is available at http://www.sun.com * + * the License. A copy of the License is available at http://www.sun.com * * * * The Original Code is BeanShell. The Initial Developer of the Original * * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright * @@ -42,12 +42,12 @@ This class should be independent of all other bsh classes! <p> - Note that tests for class existence here do *not* use the - BshClassManager, as it may require other optional class files to be - loaded. + Note that tests for class existence here do *not* use the + BshClassManager, as it may require other optional class files to be + loaded. */ @SuppressWarnings("unchecked") -public class Capabilities +public class Capabilities { private static boolean accessibility = false; @@ -65,38 +65,22 @@ If accessibility is enabled determine if the accessibility mechanism exists and if we have the optional bsh package to use it. - Note that even if both are true it does not necessarily mean that we + Note that even if both are true it does not necessarily mean that we have runtime permission to access the fields... Java security has a say in it. @see org.gjt.sp.jedit.bsh.ReflectManager */ - public static boolean haveAccessibility() + public static boolean haveAccessibility() { return accessibility; } - public static void setAccessibility( boolean b ) + public static void setAccessibility( boolean b ) throws Unavailable - { - if ( b == false ) - { - accessibility = false; - return; - } - - if ( !classExists( "java.lang.reflect.AccessibleObject" ) - || !classExists("org.gjt.sp.jedit.bsh.reflect.ReflectManagerImpl") - ) - throw new Unavailable( "Accessibility unavailable" ); - - // test basic access - try { - String.class.getDeclaredMethods(); - } catch ( SecurityException e ) { - throw new Unavailable("Accessibility unavailable: "+e); - } - - accessibility = true; + { + if (b) + throw new Unavailable("Accessibility unavailable"); + accessibility = false; } private static Hashtable classes = new Hashtable(); @@ -105,11 +89,11 @@ We should not use BshClassManager here because: a) the systems using these tests would probably not load the classes through it anyway. - b) bshclassmanager is heavy and touches other class files. + b) bshclassmanager is heavy and touches other class files. this capabilities code must be light enough to be used by any system **including the remote applet**. */ - public static boolean classExists( String name ) + public static boolean classExists( String name ) { Object c = classes.get( name ); @@ -116,7 +100,7 @@ if ( c == null ) { try { /* - Note: do *not* change this to + Note: do *not* change this to BshClassManager plainClassForName() or equivalent. This class must not touch any other bsh classes. */ @@ -140,5 +124,3 @@ public Unavailable(String s ){ super(s); } } } - - Modified: jEdit/trunk/org/gjt/sp/jedit/bsh/ClassGeneratorImpl.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/bsh/ClassGeneratorImpl.java 2023-10-13 21:05:09 UTC (rev 25696) +++ jEdit/trunk/org/gjt/sp/jedit/bsh/ClassGeneratorImpl.java 2023-10-14 11:42:01 UTC (rev 25697) @@ -6,16 +6,16 @@ import java.lang.reflect.Method; /** - + @author Pat Niemeyer (pa...@pa...) */ @SuppressWarnings("unchecked") public class ClassGeneratorImpl extends ClassGenerator { - public Class generateClass( - String name, Modifiers modifiers, - Class [] interfaces, Class superClass, BSHBlock block, - boolean isInterface, CallStack callstack, Interpreter interpreter + public Class generateClass( + String name, Modifiers modifiers, + Class [] interfaces, Class superClass, BSHBlock block, + boolean isInterface, CallStack callstack, Interpreter interpreter ) throws EvalError { @@ -39,10 +39,10 @@ Note: This method will likely be removed in the future. */ // This could be static - public void setInstanceNameSpaceParent( + public void setInstanceNameSpaceParent( Object instance, String className, NameSpace parent ) { - This ithis = + This ithis = ClassGeneratorUtil.getClassInstanceThis( instance, className ); ithis.getNameSpace().setParent( parent ); } @@ -51,29 +51,18 @@ Parse the BSHBlock for for the class definition and generate the class using ClassGenerator. */ - public static Class generateClassImpl( - String name, Modifiers modifiers, - Class [] interfaces, Class superClass, BSHBlock block, - boolean isInterface, CallStack callstack, Interpreter interpreter + public static Class generateClassImpl( + String name, Modifiers modifiers, + Class [] interfaces, Class superClass, BSHBlock block, + boolean isInterface, CallStack callstack, Interpreter interpreter ) throws EvalError { - // Scripting classes currently requires accessibility - // This can be eliminated with a bit more work. - try { - Capabilities.setAccessibility( true ); - } catch ( Capabilities.Unavailable e ) - { - throw new EvalError( - "Defining classes currently requires reflective Accessibility.", - block, callstack ); - } - NameSpace enclosingNameSpace = callstack.top(); String packageName = enclosingNameSpace.getPackage(); - String className = enclosingNameSpace.isClass ? + String className = enclosingNameSpace.isClass ? ( enclosingNameSpace.getName()+"$"+name ) : name; - String fqClassName = + String fqClassName = packageName == null ? className : packageName + "." + className; BshClassManager bcm = interpreter.getClassManager(); @@ -81,26 +70,26 @@ bcm.definingClass( fqClassName ); // Create the class static namespace - NameSpace classStaticNameSpace = + NameSpace classStaticNameSpace = new NameSpace( enclosingNameSpace, className); classStaticNameSpace.isClass = true; callstack.push( classStaticNameSpace ); - // Evaluate any inner class class definitions in the block + // Evaluate any inner class class definitions in the block // effectively recursively call this method for contained classes first - block.evalBlock( - callstack, interpreter, true/*override*/, + block.evalBlock( + callstack, interpreter, true/*override*/, ClassNodeFilter.CLASSCLASSES ); // Generate the type for our class - Variable [] variables = + Variable [] variables = getDeclaredVariables( block, callstack, interpreter, packageName ); DelayedEvalBshMethod [] methods = getDeclaredMethods( block, callstack, interpreter, packageName ); - ClassGeneratorUtil classGenerator = new ClassGeneratorUtil( - modifiers, className, packageName, superClass, interfaces, + ClassGeneratorUtil classGenerator = new ClassGeneratorUtil( + modifiers, className, packageName, superClass, interfaces, variables, methods, classStaticNameSpace, isInterface ); byte [] code = classGenerator.generateClass(); @@ -108,7 +97,7 @@ String dir = System.getProperty("debugClasses"); if ( dir != null ) try { - FileOutputStream out= + FileOutputStream out= new FileOutputStream( dir+"/"+className+".class" ); out.write(code); out.close(); @@ -121,7 +110,7 @@ enclosingNameSpace.importClass( fqClassName.replace('$','.') ); try { - classStaticNameSpace.setLocalVariable( + classStaticNameSpace.setLocalVariable( ClassGeneratorUtil.BSHINIT, block, false/*strictJava*/ ); } catch ( UtilEvalError e ) { throw new InterpreterError("unable to init static: "+e ); @@ -132,8 +121,8 @@ classStaticNameSpace.setClassStatic( genClass ); // evaluate the static portion of the block in the static space - block.evalBlock( - callstack, interpreter, true/*override*/, + block.evalBlock( + callstack, interpreter, true/*override*/, ClassNodeFilter.CLASSSTATIC ); callstack.pop(); @@ -140,11 +129,11 @@ if ( !genClass.isInterface() ) { - // Set the static bsh This callback + // Set the static bsh This callback String bshStaticFieldName = ClassGeneratorUtil.BSHSTATIC+className; try { LHS lhs = Reflect.getLHSStaticField( genClass, bshStaticFieldName ); - lhs.assign( + lhs.assign( classStaticNameSpace.getThis( interpreter ), false/*strict*/ ); } catch ( Exception e ) { throw new InterpreterError("Error in class gen setup: "+e ); @@ -155,10 +144,10 @@ return genClass; } - static Variable [] getDeclaredVariables( - BSHBlock body, CallStack callstack, Interpreter interpreter, - String defaultPackage - ) + static Variable [] getDeclaredVariables( + BSHBlock body, CallStack callstack, Interpreter interpreter, + String defaultPackage + ) { List vars = new ArrayList(); for( int child=0; child<body.jjtGetNumChildren(); child++ ) @@ -166,11 +155,11 @@ SimpleNode node = (SimpleNode)body.jjtGetChild(child); if ( node instanceof BSHTypedVariableDeclaration ) { - BSHTypedVariableDeclaration tvd = + BSHTypedVariableDeclaration tvd = (BSHTypedVariableDeclaration)node; Modifiers modifiers = tvd.modifiers; - String type = tvd.getTypeDescriptor( + String type = tvd.getTypeDescriptor( callstack, interpreter, defaultPackage ); BSHVariableDeclarator [] vardec = tvd.getDeclarators(); @@ -178,7 +167,7 @@ { String name = vardec[i].name; try { - Variable var = new Variable( + Variable var = new Variable( name, type, null/*value*/, modifiers ); vars.add( var ); } catch ( UtilEvalError e ) { @@ -191,9 +180,9 @@ return (Variable [])vars.toArray( new Variable[0] ); } - static DelayedEvalBshMethod [] getDeclaredMethods( + static DelayedEvalBshMethod [] getDeclaredMethods( BSHBlock body, CallStack callstack, Interpreter interpreter, - String defaultPackage + String defaultPackage ) throws EvalError { @@ -207,20 +196,20 @@ md.insureNodesParsed(); Modifiers modifiers = md.modifiers; String name = md.name; - String returnType = md.getReturnTypeDescriptor( + String returnType = md.getReturnTypeDescriptor( callstack, interpreter, defaultPackage ); BSHReturnType returnTypeNode = md.getReturnTypeNode(); BSHFormalParameters paramTypesNode = md.paramsNode; - String [] paramTypes = paramTypesNode.getTypeDescriptors( + String [] paramTypes = paramTypesNode.getTypeDescriptors( callstack, interpreter, defaultPackage ); - DelayedEvalBshMethod bm = new DelayedEvalBshMethod( - name, + DelayedEvalBshMethod bm = new DelayedEvalBshMethod( + name, returnType, returnTypeNode, - md.paramsNode.getParamNames(), + md.paramsNode.getParamNames(), paramTypes, paramTypesNode, md.blockNode, null/*declaringNameSpace*/, - modifiers, callstack, interpreter + modifiers, callstack, interpreter ); methods.add( bm ); @@ -227,24 +216,24 @@ } } - return (DelayedEvalBshMethod [])methods.toArray( + return (DelayedEvalBshMethod [])methods.toArray( new DelayedEvalBshMethod[0] ); } /** - A node filter that filters nodes for either a class body static - initializer or instance initializer. In the static case only static - members are passed, etc. + A node filter that filters nodes for either a class body static + initializer or instance initializer. In the static case only static + members are passed, etc. */ static class ClassNodeFilter implements BSHBlock.NodeFilter { public static final int STATIC=0, INSTANCE=1, CLASSES=2; - public static ClassNodeFilter CLASSSTATIC = + public static ClassNodeFilter CLASSSTATIC = new ClassNodeFilter( STATIC ); - public static ClassNodeFilter CLASSINSTANCE = + public static ClassNodeFilter CLASSINSTANCE = new ClassNodeFilter( INSTANCE ); - public static ClassNodeFilter CLASSCLASSES = + public static ClassNodeFilter CLASSCLASSES = new ClassNodeFilter( CLASSES ); int context; @@ -251,7 +240,7 @@ private ClassNodeFilter( int context ) { this.context = context; } - public boolean isVisible( SimpleNode node ) + public boolean isVisible( SimpleNode node ) { if ( context == CLASSES ) return node instanceof BSHClassDeclaration; @@ -270,7 +259,7 @@ return true; } - boolean isStatic( SimpleNode node ) + boolean isStatic( SimpleNode node ) { if ( node instanceof BSHTypedVariableDeclaration ) return ((BSHTypedVariableDeclaration)node).modifiers != null @@ -296,7 +285,7 @@ throws UtilEvalError, ReflectError, InvocationTargetException { String superName = ClassGeneratorUtil.BSHSUPER+methodName; - + // look for the specially named super delegate method Class clas = instance.getClass(); Method superMethod = Reflect.resolveJavaMethod( @@ -309,7 +298,7 @@ // could be a superfluous "super." which is legal. Class superClass = clas.getSuperclass(); superMethod = Reflect.resolveExpectedJavaMethod( - bcm, superClass, instance, methodName, args, + bcm, superClass, instance, methodName, args, false/*onlyStatic*/ ); return Reflect.invokeMethod( superMethod, instance, args ); } Modified: jEdit/trunk/org/gjt/sp/jedit/bsh/LHS.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/bsh/LHS.java 2023-10-13 21:05:09 UTC (rev 25696) +++ jEdit/trunk/org/gjt/sp/jedit/bsh/LHS.java 2023-10-14 11:42:01 UTC (rev 25697) @@ -7,7 +7,7 @@ * * * The contents of this file are subject to the Sun Public License Version * * 1.0 (the "License"); you may not use this file except in compliance with * - * the License. A copy of the License is available at http://www.sun.com * + * the License. A copy of the License is available at http://www.sun.com * * * * The Original Code is BeanShell. The Initial Developer of the Original * * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright * @@ -37,14 +37,14 @@ import java.lang.reflect.Field; /** - An LHS is a wrapper for an variable, field, or property. It ordinarily - holds the "left hand side" of an assignment and may be either resolved to + An LHS is a wrapper for an variable, field, or property. It ordinarily + holds the "left hand side" of an assignment and may be either resolved to a value or assigned a value. <p> - + There is one special case here termed METHOD_EVAL where the LHS is used in an intermediate evaluation of a chain of suffixes and wraps a method - invocation. In this case it may only be resolved to a value and cannot be + invocation. In this case it may only be resolved to a value and cannot be assigned. (You can't assign a value to the result of a method call e.g. "foo() = 5;"). <p> @@ -186,7 +186,7 @@ /** Assign a value to the LHS. */ - public Object assign( Object val, boolean strictJava ) + public Object assign( Object val, boolean strictJava ) throws UtilEvalError { if ( type == VARIABLE ) @@ -196,27 +196,26 @@ nameSpace.setLocalVariable( varName, val, strictJava ); else nameSpace.setVariable( varName, val, strictJava ); - } else + } else if ( type == FIELD ) { try { - Object fieldVal = val instanceof Primitive ? + Object fieldVal = val instanceof Primitive ? ((Primitive)val).getValue() : val; - // This should probably be in Reflect.java - ReflectManager.RMSetAccessible( field ); + Reflect.setAccessible( field ); field.set( object, fieldVal ); return val; } - catch( NullPointerException e) { + catch( NullPointerException e) { throw new UtilEvalError( "LHS ("+field.getName()+") not a static field."); - } - catch( IllegalAccessException e2) { + } + catch( IllegalAccessException e2) { throw new UtilEvalError( "LHS ("+field.getName()+") can't access field: "+e2); - } - catch( IllegalArgumentException e3) + } + catch( IllegalArgumentException e3) { String type = val instanceof Primitive ? ((Primitive)val).getType().getName() @@ -226,7 +225,7 @@ + " not assignable to field "+field.getName()); } } - else + else if ( type == PROPERTY ) { /* @@ -244,7 +243,7 @@ Interpreter.debug("Assignment: " + e.getMessage()); throw new UtilEvalError("No such property: " + propName); } - } else + } else if ( type == INDEX ) try { Reflect.setIndex(object, index, val); @@ -259,7 +258,7 @@ return val; } - public String toString() { + public String toString() { return "LHS: " +((field!=null)? "field = "+field.toString():"") +(varName!=null ? " varName = "+varName: "") @@ -266,4 +265,3 @@ +(nameSpace!=null ? " nameSpace = "+nameSpace.toString(): ""); } } - Modified: jEdit/trunk/org/gjt/sp/jedit/bsh/Reflect.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/bsh/Reflect.java 2023-10-13 21:05:09 UTC (rev 25696) +++ jEdit/trunk/org/gjt/sp/jedit/bsh/Reflect.java 2023-10-14 11:42:01 UTC (rev 25697) @@ -7,7 +7,7 @@ * * * The contents of this file are subject to the Sun Public License Version * * 1.0 (the "License"); you may not use this file except in compliance with * - * the License. A copy of the License is available at http://www.sun.com * + * the License. A copy of the License is available at http://www.sun.com * * * * The Original Code is BeanShell. The Initial Developer of the Original * * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright * @@ -45,11 +45,11 @@ Note: This class is messy. The method and field resolution need to be rewritten. Various methods in here catch NoSuchMethod or NoSuchField exceptions during their searches. These should be rewritten to avoid - having to catch the exceptions. Method lookups are now cached at a high + having to catch the exceptions. Method lookups are now cached at a high level so they are less important, however the logic is messy. */ @SuppressWarnings("unchecked") -class Reflect +class Reflect { /** Invoke method on arbitrary object instance. @@ -58,13 +58,13 @@ @return the result of the method call */ public static Object invokeObjectMethod( - Object object, String methodName, Object[] args, - Interpreter interpreter, CallStack callstack, SimpleNode callerInfo ) + Object object, String methodName, Object[] args, + Interpreter interpreter, CallStack callstack, SimpleNode callerInfo ) throws ReflectError, EvalError, InvocationTargetException { // Bsh scripted object if ( object instanceof This && !This.isExposedThisMethod(methodName) ) - return ((This)object).invokeMethod( + return ((This)object).invokeMethod( methodName, args, interpreter, callstack, callerInfo, false/*delcaredOnly*/ ); @@ -84,9 +84,9 @@ } } - /** + /** Invoke a method known to be static. - No object instance is needed and there is no possibility of the + No object instance is needed and there is no possibility of the method being a bsh scripted method. */ public static Object invokeStaticMethod( @@ -94,7 +94,7 @@ throws ReflectError, UtilEvalError, InvocationTargetException { Interpreter.debug("invoke static Method"); - Method method = resolveExpectedJavaMethod( + Method method = resolveExpectedJavaMethod( bcm, clas, null, methodName, args, true ); return invokeMethod( method, null, args ); } @@ -105,7 +105,7 @@ @param args may be null */ static Object invokeMethod( - Method method, Object object, Object[] args ) + Method method, Object object, Object[] args ) throws ReflectError, InvocationTargetException { if ( args == null ) @@ -139,9 +139,9 @@ return Primitive.wrap( returnValue, returnType ); } catch( IllegalAccessException e ) { - throw new ReflectError( "Cannot access method " + throw new ReflectError( "Cannot access method " + StringUtil.methodString( - method.getName(), method.getParameterTypes() ) + method.getName(), method.getParameterTypes() ) + " in '" + method.getDeclaringClass() + "' :" + e ); } } @@ -149,7 +149,7 @@ public static Object getIndex(Object array, int index) throws ReflectError, UtilTargetError { - if ( Interpreter.DEBUG ) + if ( Interpreter.DEBUG ) Interpreter.debug("getIndex: "+array+", index="+index); try { Object val = Array.get(array, index); @@ -172,7 +172,7 @@ catch( ArrayStoreException e2 ) { throw new UtilTargetError( e2 ); } catch( IllegalArgumentException e1 ) { - throw new UtilTargetError( + throw new UtilTargetError( new ArrayStoreException( e1.toString() ) ); } catch(Exception e) { throw new ReflectError("Array access:" + e); @@ -210,7 +210,7 @@ static LHS getLHSStaticField(Class clas, String fieldName) throws UtilEvalError, ReflectError { - Field f = resolveExpectedJavaField( + Field f = resolveExpectedJavaField( clas, fieldName, true/*onlystatic*/); return new LHS(f); } @@ -228,15 +228,15 @@ { // I guess this is when we pass it as an argument? // Setting locally - boolean recurse = false; + boolean recurse = false; return new LHS( ((This)object).namespace, fieldName, recurse ); } try { - Field f = resolveExpectedJavaField( + Field f = resolveExpectedJavaField( object.getClass(), fieldName, false/*staticOnly*/ ); return new LHS(object, f); - } catch ( ReflectError e ) + } catch ( ReflectError e ) { // not a field, try property access if ( hasObjectPropertySetter( object.getClass(), fieldName ) ) @@ -271,13 +271,13 @@ unecessarily. This is just a temporary impl. @return the field or null if not found */ - protected static Field resolveJavaField( + protected static Field resolveJavaField( Class clas, String fieldName, boolean staticOnly ) throws UtilEvalError { try { return resolveExpectedJavaField( clas, fieldName, staticOnly ); - } catch ( ReflectError e ) { + } catch ( ReflectError e ) { return null; } } @@ -289,7 +289,7 @@ Note: this should really just throw NoSuchFieldException... need to change related signatures and code. */ - protected static Field resolveExpectedJavaField( + protected static Field resolveExpectedJavaField( Class clas, String fieldName, boolean staticOnly ) throws UtilEvalError, ReflectError @@ -305,7 +305,7 @@ catch( NoSuchFieldException e) { throw new ReflectError("No such field: " + fieldName ); } catch ( SecurityException e ) { - throw new UtilTargetError( + throw new UtilTargetError( "Security Exception while searching fields of: "+clas, e ); } @@ -320,13 +320,13 @@ /** Used when accessibility capability is available to locate an occurrance - of the field in the most derived class or superclass and set its + of the field in the most derived class or superclass and set its accessibility flag. Note that this method is not needed in the simple non accessible case because we don't have to hunt for fields. - Note that classes may declare overlapping private fields, so the + Note that classes may declare overlapping private fields, so the distinction about the most derived is important. Java doesn't normally - allow this kind of access (super won't show private variables) so + allow this kind of access (super won't show private variables) so there is no real syntax for specifying which class scope to use... @return the Field or throws NoSuchFieldException @@ -336,7 +336,7 @@ This method should be rewritten to use getFields() and avoid catching exceptions during the search. */ - private static Field findAccessibleField( Class clas, String fieldName ) + private static Field findAccessibleField( Class clas, String fieldName ) throws UtilEvalError, NoSuchFieldException { Field field; @@ -370,7 +370,7 @@ result. If the method is not found it throws a descriptive ReflectError. */ protected static Method resolveExpectedJavaMethod( - BshClassManager bcm, Class clas, Object object, + BshClassManager bcm, Class clas, Object object, String name, Object[] args, boolean staticOnly ) throws ReflectError, UtilEvalError { @@ -406,11 +406,11 @@ flag on the method as necessary. <p/> - If, when directed to find a static method, this method locates a more - specific matching instance method it will throw a descriptive exception + If, when directed to find a static method, this method locates a more + specific matching instance method it will throw a descriptive exception analogous to the error that the Java compiler would produce. Note: as of 2.0.x this is a problem because there is no way to work - around this with a cast. + around this with a cast. <p/> @param staticOnly @@ -418,7 +418,7 @@ @return the method or null if no matching method was found. */ protected static Method resolveJavaMethod( - BshClassManager bcm, Class clas, String name, + BshClassManager bcm, Class clas, String name, Class [] types, boolean staticOnly ) throws UtilEvalError { @@ -427,7 +427,7 @@ // Lookup previously cached method Method method = null; - if ( bcm == null ) + if ( bcm == null ) Interpreter.debug("resolveJavaMethod UNOPTIMIZED lookup"); else method = bcm.getResolvedMethod( clas, name, types, staticOnly ); @@ -439,7 +439,7 @@ try { method = findOverloadedMethod( clas, name, types, publicOnly ); } catch ( SecurityException e ) { - throw new UtilTargetError( + throw new UtilTargetError( "Security Exception while searching methods of: "+clas, e ); } @@ -913,7 +913,14 @@ } } - private static void logInvokeMethod( + public static void setAccessible(Member member) + throws Capabilities.Unavailable + { + if (!isPublic(member)) + ReflectManager.RMSetAccessible( member ); + } + + private static void logInvokeMethod( String msg, Method method, Object[] args ) { if ( Interpreter.DEBUG ) @@ -955,14 +962,12 @@ private static boolean isPublic( Class c ) { return Modifier.isPublic( c.getModifiers() ); } - private static boolean isPublic( Method m ) { + + private static boolean isPublic( Member m ) { return Modifier.isPublic( m.getModifiers() ); } - private static boolean isPublic( Constructor c ) { - return Modifier.isPublic( c.getModifiers() ); - } + private static boolean isStatic( Method m ) { return Modifier.isStatic( m.getModifiers() ); } } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |