Merge
diff --git a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java
index dc172a8..9a6b5ea 100644
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java
@@ -90,9 +90,9 @@
 @ScriptClass("Global")
 public final class Global extends Scope {
     // This special value is used to flag a lazily initialized global property.
-    // This also serves as placeholder value used in place of a location property
-    // (__FILE__, __DIR__, __LINE__)
     private static final Object LAZY_SENTINEL = new Object();
+    // This serves as placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__)
+    private static final Object LOCATION_PLACEHOLDER = new Object();
 
     private static final String PACKAGE_PREFIX = "jdk.nashorn.internal.objects.";
 
@@ -916,7 +916,7 @@
     public volatile Object org;
 
     /**
-     * Getter for the Nashorn extension: Java access - global.javaImporter.
+     * Getter for the Nashorn extension: Java access - global.JavaImporter.
      *
      * @param self self reference
      * @return the value of the JavaImporter property
@@ -931,7 +931,7 @@
     }
 
     /**
-     * Setter for the Nashorn extension: Java access - global.javaImporter.
+     * Setter for the Nashorn extension: Java access - global.JavaImporter.
      *
      * @param self self reference
      * @param value value of the JavaImporter property
@@ -975,15 +975,15 @@
 
     /** Nashorn extension: current script's file name */
     @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
-    public static final Object __FILE__ = LAZY_SENTINEL;
+    public static final Object __FILE__ = LOCATION_PLACEHOLDER;
 
     /** Nashorn extension: current script's directory */
     @Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
-    public static final Object __DIR__ = LAZY_SENTINEL;
+    public static final Object __DIR__ = LOCATION_PLACEHOLDER;
 
     /** Nashorn extension: current source line number being executed */
     @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
-    public static final Object __LINE__ = LAZY_SENTINEL;
+    public static final Object __LINE__ = LOCATION_PLACEHOLDER;
 
     private volatile NativeDate DEFAULT_DATE;
 
@@ -2093,6 +2093,9 @@
     }
 
     private synchronized ScriptFunction getBuiltinJavaImporter() {
+        if (getContext().getEnv()._no_java) {
+            throw new IllegalStateException();
+        }
         if (this.builtinJavaImporter == null) {
             this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
         }
@@ -2100,6 +2103,9 @@
     }
 
     private synchronized ScriptObject getBuiltinJavaApi() {
+        if (getContext().getEnv()._no_java) {
+            throw new IllegalStateException();
+        }
         if (this.builtinJavaApi == null) {
             this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
             this.builtInJavaExtend = (ScriptFunction)builtinJavaApi.get("extend");
@@ -2325,7 +2331,7 @@
      * @return true if the value is a placeholder, false otherwise.
      */
     public static boolean isLocationPropertyPlaceholder(final Object placeholder) {
-        return placeholder == LAZY_SENTINEL;
+        return placeholder == LOCATION_PLACEHOLDER;
     }
 
     /**
@@ -2628,6 +2634,17 @@
             this.javaApi = LAZY_SENTINEL;
             this.javaImporter = LAZY_SENTINEL;
             initJavaAccess();
+        } else {
+            // delete nasgen-created global properties related to java access
+            this.delete("Java", false);
+            this.delete("JavaImporter", false);
+            this.delete("Packages", false);
+            this.delete("com", false);
+            this.delete("edu", false);
+            this.delete("java", false);
+            this.delete("javafx", false);
+            this.delete("javax", false);
+            this.delete("org", false);
         }
 
         if (! env._no_typed_arrays) {
diff --git a/test/src/jdk/nashorn/internal/runtime/test/ClassFilterTest.java b/test/src/jdk/nashorn/internal/runtime/test/ClassFilterTest.java
index 7f53540..a01e223 100644
--- a/test/src/jdk/nashorn/internal/runtime/test/ClassFilterTest.java
+++ b/test/src/jdk/nashorn/internal/runtime/test/ClassFilterTest.java
@@ -25,6 +25,7 @@
 
 package jdk.nashorn.internal.runtime.test;
 
+import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
 import java.io.File;
 import javax.script.ScriptEngine;
@@ -77,6 +78,65 @@
         } catch (final ScriptException e) {
             //emtpy
         }
+        try {
+            engine.eval("Java");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("JavaImporter");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("Packages");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("com");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("edu");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("java");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("javafx");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("javax");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            engine.eval("org");
+            fail("TypeError should have been thrown");
+        } catch (final ScriptException e) {
+            //emtpy
+        }
+        try {
+            assertEquals(engine.eval("Java = this[\"__LINE__\"]; Java === this[\"__LINE__\"]"), Boolean.TRUE);
+        } catch (final ScriptException e) {
+            fail("Unexpected exception", e);
+        }
     }
 
     @Test