8085810: Return value of Objects.requireNonNull call can be used
Reviewed-by: lagergren, attila
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java Fri Jun 05 19:05:37 2015 +0530
@@ -178,8 +178,7 @@
* denies {@code RuntimePermission("nashorn.setConfig")}
*/
public ScriptEngine getScriptEngine(final ClassFilter classFilter) {
- Objects.requireNonNull(classFilter);
- return newEngine(DEFAULT_OPTIONS, getAppClassLoader(), classFilter);
+ return newEngine(DEFAULT_OPTIONS, getAppClassLoader(), Objects.requireNonNull(classFilter));
}
/**
@@ -193,8 +192,7 @@
* denies {@code RuntimePermission("nashorn.setConfig")}
*/
public ScriptEngine getScriptEngine(final String... args) {
- Objects.requireNonNull(args);
- return newEngine(args, getAppClassLoader(), null);
+ return newEngine(Objects.requireNonNull(args), getAppClassLoader(), null);
}
/**
@@ -209,8 +207,7 @@
* denies {@code RuntimePermission("nashorn.setConfig")}
*/
public ScriptEngine getScriptEngine(final String[] args, final ClassLoader appLoader) {
- Objects.requireNonNull(args);
- return newEngine(args, appLoader, null);
+ return newEngine(Objects.requireNonNull(args), appLoader, null);
}
/**
@@ -226,9 +223,7 @@
* denies {@code RuntimePermission("nashorn.setConfig")}
*/
public ScriptEngine getScriptEngine(final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) {
- Objects.requireNonNull(args);
- Objects.requireNonNull(classFilter);
- return newEngine(args, appLoader, classFilter);
+ return newEngine(Objects.requireNonNull(args), appLoader, Objects.requireNonNull(classFilter));
}
private ScriptEngine newEngine(final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java Fri Jun 05 19:05:37 2015 +0530
@@ -255,14 +255,12 @@
@Override
public void removeMember(final String name) {
- Objects.requireNonNull(name);
- remove(name);
+ remove(Objects.requireNonNull(name));
}
@Override
public void setMember(final String name, final Object value) {
- Objects.requireNonNull(name);
- put(name, value);
+ put(Objects.requireNonNull(name), value);
}
@Override
@@ -429,7 +427,7 @@
@Override
public void putAll(final Map<? extends String, ? extends Object> map) {
- Objects.requireNonNull(map, "map is null");
+ Objects.requireNonNull(map);
final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
inGlobal(new Callable<Object>() {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/URLReader.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/URLReader.java Fri Jun 05 19:05:37 2015 +0530
@@ -78,8 +78,7 @@
* @throws NullPointerException if url is null
*/
public URLReader(final URL url, final Charset cs) {
- Objects.requireNonNull(url);
- this.url = url;
+ this.url = Objects.requireNonNull(url);
this.cs = cs;
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ParserImpl.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ParserImpl.java Fri Jun 05 19:05:37 2015 +0530
@@ -58,15 +58,13 @@
@Override
public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException {
- Objects.requireNonNull(file);
- final Source src = Source.sourceFor(file.getName(), file);
+ final Source src = Source.sourceFor(Objects.requireNonNull(file).getName(), file);
return translate(makeParser(src, listener).parse());
}
@Override
public CompilationUnitTree parse(final Path path, final DiagnosticListener listener) throws IOException, NashornException {
- Objects.requireNonNull(path);
- final Source src = Source.sourceFor(path.toString(), path);
+ final Source src = Source.sourceFor(Objects.requireNonNull(path).toString(), path);
return translate(makeParser(src, listener).parse());
}
@@ -78,9 +76,7 @@
@Override
public CompilationUnitTree parse(final String name, final Reader reader, final DiagnosticListener listener) throws IOException, NashornException {
- Objects.requireNonNull(name);
- Objects.requireNonNull(reader);
- final Source src = Source.sourceFor(name, reader);
+ final Source src = Source.sourceFor(Objects.requireNonNull(name), Objects.requireNonNull(reader));
return translate(makeParser(src, listener).parse());
}
@@ -92,8 +88,7 @@
@Override
public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
- Objects.requireNonNull(scriptObj);
- final Map<?,?> map = scriptObj;
+ final Map<?,?> map = Objects.requireNonNull(scriptObj);
if (map.containsKey("script") && map.containsKey("name")) {
final String script = JSType.toString(map.get("script"));
final String name = JSType.toString(map.get("name"));
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompileUnit.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompileUnit.java Fri Jun 05 19:05:37 2015 +0530
@@ -122,8 +122,7 @@
* @param clazz class with code for this compile unit
*/
void setCode(final Class<?> clazz) {
- Objects.requireNonNull(clazz);
- this.clazz = clazz;
+ this.clazz = Objects.requireNonNull(clazz);
// Revisit this - refactor to avoid null-ed out non-final fields
// null out emitter
this.classEmitter = null;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java Fri Jun 05 19:05:37 2015 +0530
@@ -1005,9 +1005,7 @@
* @return the global singleton
*/
public static Global instance() {
- final Global global = Context.getGlobal();
- Objects.requireNonNull(global);
- return global;
+ return Objects.requireNonNull(Context.getGlobal());
}
private static Global instanceFrom(final Object self) {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java Fri Jun 05 19:05:37 2015 +0530
@@ -70,7 +70,6 @@
* @return Installed class.
*/
synchronized Class<?> installClass(final String name, final byte[] data, final CodeSource cs) {
- Objects.requireNonNull(cs);
- return defineClass(name, data, 0, data.length, cs);
+ return defineClass(name, data, 0, data.length, Objects.requireNonNull(cs));
}
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapter.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapter.java Fri Jun 05 19:05:37 2015 +0530
@@ -36,8 +36,7 @@
private final Object adapter;
JavaSuperAdapter(final Object adapter) {
- Objects.requireNonNull(adapter);
- this.adapter = adapter;
+ this.adapter = Objects.requireNonNull(adapter);
}
public Object getAdapter() {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/options/Options.java Fri Jun 05 12:38:53 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/options/Options.java Fri Jun 05 19:05:37 2015 +0530
@@ -136,6 +136,12 @@
return options.toString();
}
+ private static void checkPropertyName(final String name) {
+ if (! Objects.requireNonNull(name).startsWith("nashorn.")) {
+ throw new IllegalArgumentException(name);
+ }
+ }
+
/**
* Convenience function for getting system properties in a safe way
@@ -144,11 +150,7 @@
* @return true if set to true, default value if unset or set to false
*/
public static boolean getBooleanProperty(final String name, final Boolean defValue) {
- Objects.requireNonNull(name);
- if (!name.startsWith("nashorn.")) {
- throw new IllegalArgumentException(name);
- }
-
+ checkPropertyName(name);
return AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
@Override
@@ -185,11 +187,7 @@
* @return string property if set or default value
*/
public static String getStringProperty(final String name, final String defValue) {
- Objects.requireNonNull(name);
- if (! name.startsWith("nashorn.")) {
- throw new IllegalArgumentException(name);
- }
-
+ checkPropertyName(name);
return AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
@@ -212,11 +210,7 @@
* @return integer property if set or default value
*/
public static int getIntProperty(final String name, final int defValue) {
- Objects.requireNonNull(name);
- if (! name.startsWith("nashorn.")) {
- throw new IllegalArgumentException(name);
- }
-
+ checkPropertyName(name);
return AccessController.doPrivileged(
new PrivilegedAction<Integer>() {
@Override