From 20bfcfa75ac514af49e2d5afa1183f73da8476f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Thu, 13 Nov 2014 15:29:22 +0100 Subject: [PATCH] 8064789: Nashorn should just warn on code store instantiation error Reviewed-by: attila, lagergren --- .../jdk/nashorn/internal/runtime/CodeStore.java | 16 ++++++++++------ .../jdk/nashorn/internal/runtime/Context.java | 8 ++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java index 0e85beebbd7..4e745ff47fe 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java @@ -82,10 +82,9 @@ public abstract class CodeStore implements Loggable { * Returns a new code store instance. * * @param context the current context - * @return The instance - * @throws IOException If an error occurs + * @return The instance, or null if code store could not be created */ - public static CodeStore newCodeStore(final Context context) throws IOException { + public static CodeStore newCodeStore(final Context context) { final Class baseClass = CodeStore.class; try { // security check first @@ -103,9 +102,14 @@ public abstract class CodeStore implements Loggable { } catch (final AccessControlException e) { context.getLogger(CodeStore.class).warning("failed to load code store provider ", e); } - final CodeStore store = new DirectoryCodeStore(context); - store.initLogger(context); - return store; + try { + final CodeStore store = new DirectoryCodeStore(context); + store.initLogger(context); + return store; + } catch (final IOException e) { + context.getLogger(CodeStore.class).warning("failed to create cache directory ", e); + return null; + } } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java index 8887fb45a13..b1342c7e528 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java @@ -509,11 +509,7 @@ public final class Context { } if (env._persistent_cache) { - try { - codeStore = newCodeStore(this); - } catch (final IOException e) { - throw new RuntimeException("Error initializing code cache", e); - } + codeStore = newCodeStore(this); } // print version info if asked. @@ -1200,7 +1196,7 @@ public final class Context { FunctionNode functionNode = null; // We only use the code store here if optimistic types are disabled. With optimistic types, initial compilation // just creates a thin wrapper, and actual code is stored per function in RecompilableScriptFunctionData. - final boolean useCodeStore = env._persistent_cache && !env._parse_only && !env._optimistic_types; + final boolean useCodeStore = codeStore != null && !env._parse_only && !env._optimistic_types; final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null; if (useCodeStore) {