diff --git a/build.xml b/build.xml index 0d30c51..cd3c67a 100644 --- a/build.xml +++ b/build.xml @@ -159,6 +159,7 @@ excludes="${excludes},**/bak/**" source="${ant.build.javac.source}" target="${ant.build.javac.target}" + includeantruntime="false" > @@ -193,6 +194,7 @@ excludes="${excludes},**/bak/**" source="${ant.build.javac.source}" target="${ant.build.javac.target}" + includeantruntime="false" > diff --git a/dist/bsh-2.1.9.jar b/dist/bsh-2.1.9.jar deleted file mode 100644 index c169a30..0000000 Binary files a/dist/bsh-2.1.9.jar and /dev/null differ diff --git a/dist/bsh-2.1.9.jar.sha512sum b/dist/bsh-2.1.9.jar.sha512sum deleted file mode 100644 index fc42bc0..0000000 --- a/dist/bsh-2.1.9.jar.sha512sum +++ /dev/null @@ -1 +0,0 @@ -0f5f4e6801e50b19be719f9ecf60f1be9d860656189050eb40d2116e986a2a37285de10b03181d3f10a568efb3eec00df2a169af8cd0314428eb3dfdc7496ef8 bsh-2.1.9.jar diff --git a/src/bsh/BSHLiteral.java b/src/bsh/BSHLiteral.java index 06a60f3..100b120 100644 --- a/src/bsh/BSHLiteral.java +++ b/src/bsh/BSHLiteral.java @@ -99,7 +99,7 @@ public void charSetup(String str) ch = getEscapeChar(ch); } - value = new Primitive(new Character(ch).charValue()); + value = new Primitive(Character.valueOf(ch).charValue()); } void stringSetup(String str) diff --git a/src/bsh/BSHUnaryExpression.java b/src/bsh/BSHUnaryExpression.java index 6ae7e28..f3508f2 100644 --- a/src/bsh/BSHUnaryExpression.java +++ b/src/bsh/BSHUnaryExpression.java @@ -101,7 +101,7 @@ private Object primitiveWrapperUnaryOperation(Object val, int kind) Object operand = Primitive.promoteToInteger(val); if ( operand instanceof Boolean ) - return new Boolean( + return Boolean.valueOf( Primitive.booleanUnaryOperation((Boolean)operand, kind)); else if ( operand instanceof Integer ) @@ -112,21 +112,21 @@ private Object primitiveWrapperUnaryOperation(Object val, int kind) if(kind == INCR || kind == DECR) { if(operandType == Byte.TYPE) - return new Byte((byte)result); + return Byte.valueOf((byte)result); if(operandType == Short.TYPE) - return new Short((short)result); + return Short.valueOf((short)result); if(operandType == Character.TYPE) - return new Character((char)result); + return Character.valueOf((char)result); } - return new Integer(result); + return Integer.valueOf(result); } else if(operand instanceof Long) - return new Long(Primitive.longUnaryOperation((Long)operand, kind)); + return Long.valueOf(Primitive.longUnaryOperation((Long)operand, kind)); else if(operand instanceof Float) - return new Float(Primitive.floatUnaryOperation((Float)operand, kind)); + return Float.valueOf(Primitive.floatUnaryOperation((Float)operand, kind)); else if(operand instanceof Double) - return new Double(Primitive.doubleUnaryOperation((Double)operand, kind)); + return Double.valueOf(Primitive.doubleUnaryOperation((Double)operand, kind)); else throw new InterpreterError("An error occurred. Please call technical support."); } diff --git a/src/bsh/BshClassManager.java b/src/bsh/BshClassManager.java index 253146b..bbc5746 100644 --- a/src/bsh/BshClassManager.java +++ b/src/bsh/BshClassManager.java @@ -147,7 +147,7 @@ public static BshClassManager createClassManager( Interpreter interpreter ) // Try to load the module // don't refer to it directly here or we're dependent upon it Class clazz = Class.forName( "bsh.classpath.ClassManagerImpl" ); - manager = (BshClassManager) clazz.newInstance(); + manager = (BshClassManager) clazz.getDeclaredConstructor().newInstance(); } catch ( Exception e ) { throw new InterpreterError("Error loading classmanager", e); } diff --git a/src/bsh/NameSpace.java b/src/bsh/NameSpace.java index bf4988f..bed2b74 100644 --- a/src/bsh/NameSpace.java +++ b/src/bsh/NameSpace.java @@ -598,6 +598,7 @@ protected Object unwrapVariable( Variable var ) /** @deprecated See #setTypedVariable( String, Class, Object, Modifiers ) */ + @Deprecated public void setTypedVariable( String name, Class type, Object value, boolean isFinal ) throws UtilEvalError @@ -1526,4 +1527,4 @@ private List clone(final List list) { return new ArrayList(list); } -} \ No newline at end of file +} diff --git a/src/bsh/Primitive.java b/src/bsh/Primitive.java index 965965b..222148c 100644 --- a/src/bsh/Primitive.java +++ b/src/bsh/Primitive.java @@ -160,14 +160,14 @@ public Primitive( Object value ) this.value = value; } - public Primitive(boolean value) { this(new Boolean(value)); } - public Primitive(byte value) { this(new Byte(value)); } - public Primitive(short value) { this(new Short(value)); } - public Primitive(char value) { this(new Character(value)); } - public Primitive(int value) { this(new Integer(value)); } - public Primitive(long value) { this(new Long(value)); } - public Primitive(float value) { this(new Float(value)); } - public Primitive(double value) { this(new Double(value)); } + public Primitive(boolean value) { this(Boolean.valueOf(value)); } + public Primitive(byte value) { this(Byte.valueOf(value)); } + public Primitive(short value) { this(Short.valueOf(value)); } + public Primitive(char value) { this(Character.valueOf(value)); } + public Primitive(int value) { this(Integer.valueOf(value)); } + public Primitive(long value) { this(Long.valueOf(value)); } + public Primitive(float value) { this(Float.valueOf(value)); } + public Primitive(double value) { this(Double.valueOf(value)); } /** Return the primitive value stored in its java.lang wrapper class @@ -291,23 +291,23 @@ static Boolean booleanBinaryOperation(Boolean B1, Boolean B2, int kind) switch(kind) { case EQ: - return new Boolean(lhs == rhs); + return Boolean.valueOf(lhs == rhs); case NE: - return new Boolean(lhs != rhs); + return Boolean.valueOf(lhs != rhs); case BOOL_OR: case BOOL_ORX: case BIT_OR: - return new Boolean( lhs || rhs ); + return Boolean.valueOf( lhs || rhs ); case BOOL_AND: case BOOL_ANDX: case BIT_AND: - return new Boolean( lhs && rhs ); + return Boolean.valueOf( lhs && rhs ); case XOR: - return new Boolean( lhs ^ rhs ); + return Boolean.valueOf( lhs ^ rhs ); default: throw new InterpreterError("unimplemented binary operator"); @@ -325,65 +325,65 @@ static Object longBinaryOperation(Long L1, Long L2, int kind) // boolean case LT: case LTX: - return new Boolean(lhs < rhs); + return Boolean.valueOf(lhs < rhs); case GT: case GTX: - return new Boolean(lhs > rhs); + return Boolean.valueOf(lhs > rhs); case EQ: - return new Boolean(lhs == rhs); + return Boolean.valueOf(lhs == rhs); case LE: case LEX: - return new Boolean(lhs <= rhs); + return Boolean.valueOf(lhs <= rhs); case GE: case GEX: - return new Boolean(lhs >= rhs); + return Boolean.valueOf(lhs >= rhs); case NE: - return new Boolean(lhs != rhs); + return Boolean.valueOf(lhs != rhs); // arithmetic case PLUS: - return new Long(lhs + rhs); + return Long.valueOf(lhs + rhs); case MINUS: - return new Long(lhs - rhs); + return Long.valueOf(lhs - rhs); case STAR: - return new Long(lhs * rhs); + return Long.valueOf(lhs * rhs); case SLASH: - return new Long(lhs / rhs); + return Long.valueOf(lhs / rhs); case MOD: - return new Long(lhs % rhs); + return Long.valueOf(lhs % rhs); // bitwise case LSHIFT: case LSHIFTX: - return new Long(lhs << rhs); + return Long.valueOf(lhs << rhs); case RSIGNEDSHIFT: case RSIGNEDSHIFTX: - return new Long(lhs >> rhs); + return Long.valueOf(lhs >> rhs); case RUNSIGNEDSHIFT: case RUNSIGNEDSHIFTX: - return new Long(lhs >>> rhs); + return Long.valueOf(lhs >>> rhs); case BIT_AND: case BIT_ANDX: - return new Long(lhs & rhs); + return Long.valueOf(lhs & rhs); case BIT_OR: case BIT_ORX: - return new Long(lhs | rhs); + return Long.valueOf(lhs | rhs); case XOR: - return new Long(lhs ^ rhs); + return Long.valueOf(lhs ^ rhs); default: throw new InterpreterError( @@ -402,65 +402,65 @@ static Object intBinaryOperation(Integer I1, Integer I2, int kind) // boolean case LT: case LTX: - return new Boolean(lhs < rhs); + return Boolean.valueOf(lhs < rhs); case GT: case GTX: - return new Boolean(lhs > rhs); + return Boolean.valueOf(lhs > rhs); case EQ: - return new Boolean(lhs == rhs); + return Boolean.valueOf(lhs == rhs); case LE: case LEX: - return new Boolean(lhs <= rhs); + return Boolean.valueOf(lhs <= rhs); case GE: case GEX: - return new Boolean(lhs >= rhs); + return Boolean.valueOf(lhs >= rhs); case NE: - return new Boolean(lhs != rhs); + return Boolean.valueOf(lhs != rhs); // arithmetic case PLUS: - return new Integer(lhs + rhs); + return Integer.valueOf(lhs + rhs); case MINUS: - return new Integer(lhs - rhs); + return Integer.valueOf(lhs - rhs); case STAR: - return new Integer(lhs * rhs); + return Integer.valueOf(lhs * rhs); case SLASH: - return new Integer(lhs / rhs); + return Integer.valueOf(lhs / rhs); case MOD: - return new Integer(lhs % rhs); + return Integer.valueOf(lhs % rhs); // bitwise case LSHIFT: case LSHIFTX: - return new Integer(lhs << rhs); + return Integer.valueOf(lhs << rhs); case RSIGNEDSHIFT: case RSIGNEDSHIFTX: - return new Integer(lhs >> rhs); + return Integer.valueOf(lhs >> rhs); case RUNSIGNEDSHIFT: case RUNSIGNEDSHIFTX: - return new Integer(lhs >>> rhs); + return Integer.valueOf(lhs >>> rhs); case BIT_AND: case BIT_ANDX: - return new Integer(lhs & rhs); + return Integer.valueOf(lhs & rhs); case BIT_OR: case BIT_ORX: - return new Integer(lhs | rhs); + return Integer.valueOf(lhs | rhs); case XOR: - return new Integer(lhs ^ rhs); + return Integer.valueOf(lhs ^ rhs); default: throw new InterpreterError( @@ -480,41 +480,41 @@ static Object doubleBinaryOperation(Double D1, Double D2, int kind) // boolean case LT: case LTX: - return new Boolean(lhs < rhs); + return Boolean.valueOf(lhs < rhs); case GT: case GTX: - return new Boolean(lhs > rhs); + return Boolean.valueOf(lhs > rhs); case EQ: - return new Boolean(lhs == rhs); + return Boolean.valueOf(lhs == rhs); case LE: case LEX: - return new Boolean(lhs <= rhs); + return Boolean.valueOf(lhs <= rhs); case GE: case GEX: - return new Boolean(lhs >= rhs); + return Boolean.valueOf(lhs >= rhs); case NE: - return new Boolean(lhs != rhs); + return Boolean.valueOf(lhs != rhs); // arithmetic case PLUS: - return new Double(lhs + rhs); + return Double.valueOf(lhs + rhs); case MINUS: - return new Double(lhs - rhs); + return Double.valueOf(lhs - rhs); case STAR: - return new Double(lhs * rhs); + return Double.valueOf(lhs * rhs); case SLASH: - return new Double(lhs / rhs); + return Double.valueOf(lhs / rhs); case MOD: - return new Double(lhs % rhs); + return Double.valueOf(lhs % rhs); // can't shift floating-point values case LSHIFT: @@ -542,41 +542,41 @@ static Object floatBinaryOperation(Float F1, Float F2, int kind) // boolean case LT: case LTX: - return new Boolean(lhs < rhs); + return Boolean.valueOf(lhs < rhs); case GT: case GTX: - return new Boolean(lhs > rhs); + return Boolean.valueOf(lhs > rhs); case EQ: - return new Boolean(lhs == rhs); + return Boolean.valueOf(lhs == rhs); case LE: case LEX: - return new Boolean(lhs <= rhs); + return Boolean.valueOf(lhs <= rhs); case GE: case GEX: - return new Boolean(lhs >= rhs); + return Boolean.valueOf(lhs >= rhs); case NE: - return new Boolean(lhs != rhs); + return Boolean.valueOf(lhs != rhs); // arithmetic case PLUS: - return new Float(lhs + rhs); + return Float.valueOf(lhs + rhs); case MINUS: - return new Float(lhs - rhs); + return Float.valueOf(lhs - rhs); case STAR: - return new Float(lhs * rhs); + return Float.valueOf(lhs * rhs); case SLASH: - return new Float(lhs / rhs); + return Float.valueOf(lhs / rhs); case MOD: - return new Float(lhs % rhs); + return Float.valueOf(lhs % rhs); // can't shift floats case LSHIFT: @@ -599,9 +599,9 @@ static Object floatBinaryOperation(Float F1, Float F2, int kind) static Object promoteToInteger(Object wrapper ) { if(wrapper instanceof Character) - return new Integer(((Character)wrapper).charValue()); + return Integer.valueOf(((Character)wrapper).charValue()); else if((wrapper instanceof Byte) || (wrapper instanceof Short)) - return new Integer(((Number)wrapper).intValue()); + return Integer.valueOf(((Number)wrapper).intValue()); return wrapper; } @@ -625,23 +625,23 @@ static Object[] promotePrimitives(Object lhs, Object rhs) if((b = (lnum instanceof Double)) || (rnum instanceof Double)) { if(b) - rhs = new Double(rnum.doubleValue()); + rhs = Double.valueOf(rnum.doubleValue()); else - lhs = new Double(lnum.doubleValue()); + lhs = Double.valueOf(lnum.doubleValue()); } else if((b = (lnum instanceof Float)) || (rnum instanceof Float)) { if(b) - rhs = new Float(rnum.floatValue()); + rhs = Float.valueOf(rnum.floatValue()); else - lhs = new Float(lnum.floatValue()); + lhs = Float.valueOf(lnum.floatValue()); } else if((b = (lnum instanceof Long)) || (rnum instanceof Long)) { if(b) - rhs = new Long(rnum.longValue()); + rhs = Long.valueOf(rnum.longValue()); else - lhs = new Long(lnum.longValue()); + lhs = Long.valueOf(lnum.longValue()); } } @@ -807,7 +807,7 @@ public Number numberValue() throws UtilEvalError // Promote character to Number type for these purposes if (value instanceof Character) - value = new Integer(((Character)value).charValue()); + value = Integer.valueOf(((Character)value).charValue()); if (value instanceof Number) return (Number)value; @@ -1105,7 +1105,7 @@ static Object castWrapper( // first promote char to Number type to avoid duplicating code if ( value instanceof Character ) - value = new Integer(((Character)value).charValue()); + value = Integer.valueOf(((Character)value).charValue()); if ( !(value instanceof Number) ) throw new InterpreterError("bad type in cast"); @@ -1113,19 +1113,19 @@ static Object castWrapper( Number number = (Number)value; if (toType == Byte.TYPE) - return new Byte(number.byteValue()); + return Byte.valueOf(number.byteValue()); if (toType == Short.TYPE) - return new Short(number.shortValue()); + return Short.valueOf(number.shortValue()); if (toType == Character.TYPE) - return new Character((char)number.intValue()); + return Character.valueOf((char)number.intValue()); if (toType == Integer.TYPE) - return new Integer(number.intValue()); + return Integer.valueOf(number.intValue()); if (toType == Long.TYPE) - return new Long(number.longValue()); + return Long.valueOf(number.longValue()); if (toType == Float.TYPE) - return new Float(number.floatValue()); + return Float.valueOf(number.floatValue()); if (toType == Double.TYPE) - return new Double(number.doubleValue()); + return Double.valueOf(number.doubleValue()); throw new InterpreterError("error in wrapper cast"); } diff --git a/src/bsh/Reflect.java b/src/bsh/Reflect.java index 478fb89..ea64db7 100644 --- a/src/bsh/Reflect.java +++ b/src/bsh/Reflect.java @@ -67,23 +67,56 @@ final class Reflect { private static final boolean CHECK_MODULE_ACCESSIBILITY = true; private static final MethodHandle trySetAccessible; - + private static final MethodHandle getModule; + private static final MethodHandle isExported; + private static final Object myModule; + static { - MethodHandle methodHandle = null; - if (CHECK_MODULE_ACCESSIBILITY) { - try { - final Method method = AccessibleObject.class.getDeclaredMethod("trySetAccessible"); - methodHandle = MethodHandles.lookup().unreflect(method); - } catch (NoSuchMethodException | IllegalAccessException e) { - // ignore - } - } - trySetAccessible = methodHandle; + if (CHECK_MODULE_ACCESSIBILITY) { + + // Get methodHandle for trySetAccessible if it exists in this version + MethodHandle methodHandle = null; + try { + final Method method = AccessibleObject.class.getDeclaredMethod("trySetAccessible"); + methodHandle = MethodHandles.lookup().unreflect(method); + } catch (NoSuchMethodException | IllegalAccessException e) { + // ignore + } + trySetAccessible = methodHandle; + + // Get methodHandle for getModule if it exists in this version + methodHandle = null; + Object mod = null; + try { + Method method = Class.class.getDeclaredMethod("getModule"); + methodHandle = MethodHandles.lookup().unreflect(method); + mod = methodHandle.invoke(Reflect.class); + } catch (Throwable th) { + // ignore + } + getModule = methodHandle; + myModule = mod; + + // Get methodHandle for isExported if it exists in this version + methodHandle = null; + try { + Class clz = Reflect.class.getClassLoader().loadClass("java.lang.Module"); + if (clz != null) { + Method method = clz.getDeclaredMethod("isExported", String.class); + methodHandle = MethodHandles.lookup().unreflect(method); + } + } catch (Exception ex) { + ex.printStackTrace(); + // ignore + } + isExported = methodHandle; + + } } /** - * A comperator wich sorts methods according to {@@link #getVisibility}. + * A comperator wich sorts methods according to {@link #getVisibility}. */ public static final Comparator METHOD_COMPARATOR = new Comparator() { public int compare(final Method a, final Method b) { @@ -920,6 +953,31 @@ private static boolean trySetAccessible(AccessibleObject accessibleObject) { if (trySetAccessible == null) { return true; } + + /* + * If running under JDK9+ then check to see if the + * package has been exported from its module. + * If is hasn't then do not trySetAccessible + * because this will either print a warning message + * or the behaviour will change in future + * versions. + */ + if (myModule != null && isExported != null) { + try { + Class declaringClass = ((Member)accessibleObject).getDeclaringClass(); + Object them = getModule.invoke(declaringClass); + if (myModule != them) { + String pkg = declaringClass.getName(); + pkg = pkg.substring(0,pkg.lastIndexOf('.')); + boolean ie = (boolean)isExported.invoke(them, pkg); + if (!ie) + return false; + } + } catch (Throwable th) { + // Ignore + } + } + try { final boolean result = (Boolean) trySetAccessible.invoke(accessibleObject); return result; @@ -983,4 +1041,4 @@ public boolean add(final T t) { } } -} \ No newline at end of file +} diff --git a/src/bsh/This.java b/src/bsh/This.java index 22ef489..cb3685f 100644 --- a/src/bsh/This.java +++ b/src/bsh/This.java @@ -121,7 +121,7 @@ public Object getInterface( Class [] ca ) int hash = 21; for(int i=0; i 0 ) { + if ( (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) > 0 ) { replaceRange( "", cmdStart, textLength()); histLine = 0; e.consume(); @@ -281,7 +281,7 @@ private synchronized void type( KeyEvent e ) { // Control-C case ( KeyEvent.VK_C ): if (text.getSelectedText() == null) { - if (( (e.getModifiers() & InputEvent.CTRL_MASK) > 0 ) + if (( (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) > 0 ) && (e.getID() == KeyEvent.KEY_PRESSED)) { append("^C"); } @@ -299,9 +299,9 @@ private synchronized void type( KeyEvent e ) { default: if ( - (e.getModifiers() & - (InputEvent.CTRL_MASK - | InputEvent.ALT_MASK | InputEvent.META_MASK)) == 0 ) + (e.getModifiersEx() & + (InputEvent.CTRL_DOWN_MASK + | InputEvent.ALT_DOWN_MASK | InputEvent.META_DOWN_MASK)) == 0 ) { // plain character forceCaretMoveToEnd();