Merge
authorlana
Thu, 09 Jun 2016 19:07:12 +0000
changeset 38900 35214991a264
parent 38896 db87ac7c7464 (current diff)
parent 38899 b4b3d017b651 (diff)
child 38901 28e775c6e08e
Merge
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Console.java	Thu Jun 09 17:28:39 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Console.java	Thu Jun 09 19:07:12 2016 +0000
@@ -59,7 +59,8 @@
         in.setHandleUserInterrupt(true);
         in.setBellEnabled(true);
         in.setCopyPasteDetection(true);
-        in.setHistory(new EditingHistory(in, Files.readAllLines(historyFile.toPath())) {
+        final Iterable<String> existingHistory = historyFile.exists() ? Files.readAllLines(historyFile.toPath()) : null;
+        in.setHistory(new EditingHistory(in, existingHistory) {
             @Override protected boolean isComplete(CharSequence input) {
                 return completer.isComplete(input.toString());
             }
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java	Thu Jun 09 17:28:39 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java	Thu Jun 09 19:07:12 2016 +0000
@@ -117,7 +117,7 @@
         final PrintWriter err = context.getErr();
         final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
-        final PropertiesHelper propsHelper = new PropertiesHelper(env._classpath);
+        final PropertiesHelper propsHelper = new PropertiesHelper(context);
         final NashornCompleter completer = new NashornCompleter(context, global, this, propsHelper);
 
         try (final Console in = new Console(System.in, System.out, HIST_FILE, completer,
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/PackagesHelper.java	Thu Jun 09 17:28:39 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/PackagesHelper.java	Thu Jun 09 19:07:12 2016 +0000
@@ -25,6 +25,7 @@
 
 package jdk.nashorn.tools.jjs;
 
+import java.lang.reflect.Modifier;
 import java.io.IOException;
 import java.io.File;
 import java.net.URI;
@@ -49,6 +50,7 @@
 import javax.tools.StandardJavaFileManager;
 import javax.tools.StandardLocation;
 import javax.tools.ToolProvider;
+import jdk.nashorn.internal.runtime.Context;
 
 /**
  * A helper class to compute properties of a Java package object. Properties of
@@ -72,6 +74,7 @@
         return compiler != null;
     }
 
+    private final Context context;
     private final StandardJavaFileManager fm;
     private final Set<JavaFileObject.Kind> fileKinds;
     private final FileSystem jrtfs;
@@ -79,9 +82,11 @@
     /**
      * Construct a new PackagesHelper.
      *
-     * @param classPath Class path to compute properties of java package objects
+     * @param context the current Nashorn Context
      */
-    PackagesHelper(final String classPath) throws IOException {
+    PackagesHelper(final Context context) throws IOException {
+        this.context = context;
+        final String classPath = context.getEnv()._classpath;
         if (isJavacAvailable()) {
             fm = compiler.getStandardFileManager(null, null, null);
             fileKinds = EnumSet.of(JavaFileObject.Kind.CLASS);
@@ -166,8 +171,11 @@
                                 String str = p.getFileName().toString();
                                 // get rid of ".class", if any
                                 if (str.endsWith(".class")) {
-                                    props.add(str.substring(0, str.length() - ".class".length()));
-                                } else {
+                                    final String clsName = str.substring(0, str.length() - ".class".length());
+                                    if (clsName.indexOf('$') == -1 && isClassAccessible(pkg + "." + clsName)) {
+                                        props.add(str);
+                                    }
+                                } else if (isPackageAccessible(pkg + "." + str)) {
                                     props.add(str);
                                 }
                             }
@@ -193,7 +201,10 @@
 
             if (nextDot != -1) {
                 // subpackage - eg. "regex" for "java.util"
-                props.add(binaryName.substring(start, nextDot));
+                final String pkgName = binaryName.substring(start, nextDot);
+                if (isPackageAccessible(binaryName.substring(0, nextDot))) {
+                    props.add(binaryName.substring(start, nextDot));
+                }
             } else {
                 // class - filter out nested, inner, anonymous, local classes.
                 // Dynalink supported public nested classes as properties of
@@ -201,7 +212,7 @@
                 // "$" internal names as properties of package object.
 
                 final String clsName = binaryName.substring(start);
-                if (clsName.indexOf('$') == -1) {
+                if (clsName.indexOf('$') == -1 && isClassAccessible(binaryName)) {
                     props.add(clsName);
                 }
             }
@@ -214,4 +225,22 @@
                     .map(File::new)
                     .collect(Collectors.toList());
     }
+
+    private boolean isClassAccessible(final String className) {
+        try {
+            final Class<?> clz = context.findClass(className);
+            return Modifier.isPublic(clz.getModifiers());
+        } catch (final ClassNotFoundException cnfe) {
+        }
+        return false;
+    }
+
+    private boolean isPackageAccessible(final String pkgName) {
+        try {
+            Context.checkPackageAccess(pkgName);
+            return true;
+        } catch (final SecurityException se) {
+            return false;
+        }
+    }
 }
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/PropertiesHelper.java	Thu Jun 09 17:28:39 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/PropertiesHelper.java	Thu Jun 09 19:07:12 2016 +0000
@@ -33,6 +33,7 @@
 import java.util.WeakHashMap;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.NativeJavaPackage;
 import jdk.nashorn.internal.runtime.PropertyMap;
@@ -52,11 +53,11 @@
     /**
      * Construct a new PropertiesHelper.
      *
-     * @param classPath Class path to compute properties of java package objects
+     * @param context the current nashorn Context
      */
-    PropertiesHelper(final String classPath) {
+    PropertiesHelper(final Context context) {
         try {
-            this.pkgsHelper = new PackagesHelper(classPath);
+            this.pkgsHelper = new PackagesHelper(context);
         } catch (final IOException exp) {
             if (Main.DEBUG) {
                 exp.printStackTrace();
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu Jun 09 17:28:39 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu Jun 09 19:07:12 2016 +0000
@@ -286,7 +286,7 @@
         superClassName = Type.getInternalName(superClass);
         generatedClassName = getGeneratedClassName(superClass, interfaces);
 
-        cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER, generatedClassName, null, superClassName, getInternalTypeNames(interfaces));
+        cw.visit(Opcodes.V1_8, ACC_PUBLIC | ACC_SUPER, generatedClassName, null, superClassName, getInternalTypeNames(interfaces));
         generateField(GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
         generateField(DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
 
@@ -1031,7 +1031,9 @@
         if (!constructor && Modifier.isInterface(owner.getModifiers())) {
             // we should call default method on the immediate "super" type - not on (possibly)
             // the indirectly inherited interface class!
-            mv.invokespecial(Type.getInternalName(findInvokespecialOwnerFor(owner)), name, methodDesc, false);
+            final Class<?> superType = findInvokespecialOwnerFor(owner);
+            mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(superType), name, methodDesc,
+                Modifier.isInterface(superType.getModifiers()));
         } else {
             mv.invokespecial(superClassName, name, methodDesc, false);
         }