8026250: Logging nullpointer bugfix and javadoc warnings
Reviewed-by: hannesw, jlaskey, sundar
--- a/nashorn/src/jdk/nashorn/api/scripting/JSObject.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/api/scripting/JSObject.java Thu Oct 10 16:16:20 2013 +0200
@@ -46,7 +46,7 @@
* @param args arguments to method
* @return result of call
*/
- public Object call(Object thiz, Object... args) {
+ public Object call(final Object thiz, final Object... args) {
throw new UnsupportedOperationException("call");
}
@@ -57,7 +57,7 @@
* @param args arguments to method
* @return result of constructor call
*/
- public Object newObject(Object... args) {
+ public Object newObject(final Object... args) {
throw new UnsupportedOperationException("newObject");
}
@@ -67,7 +67,7 @@
* @param s JavaScript expression to evaluate
* @return evaluation result
*/
- public Object eval(String s) {
+ public Object eval(final String s) {
throw new UnsupportedOperationException("eval");
}
@@ -78,7 +78,7 @@
* @param args arguments to be passed to the member function
* @return result of call
*/
- public Object callMember(String name, Object... args) {
+ public Object callMember(final String name, final Object... args) {
throw new UnsupportedOperationException("call");
}
@@ -88,7 +88,7 @@
* @param name of member
* @return member
*/
- public Object getMember(String name) {
+ public Object getMember(final String name) {
return null;
}
@@ -98,7 +98,7 @@
* @param index index slot to retrieve
* @return member
*/
- public Object getSlot(int index) {
+ public Object getSlot(final int index) {
return null;
}
@@ -108,7 +108,7 @@
* @param name name of member
* @return true if this object has a member of the given name
*/
- public boolean hasMember(String name) {
+ public boolean hasMember(final String name) {
return false;
}
@@ -118,7 +118,7 @@
* @param slot index to check
* @return true if this object has a slot
*/
- public boolean hasSlot(int slot) {
+ public boolean hasSlot(final int slot) {
return false;
}
@@ -127,7 +127,8 @@
*
* @param name name of the member
*/
- public void removeMember(String name) {
+ public void removeMember(final String name) {
+ //empty
}
/**
@@ -136,7 +137,8 @@
* @param name name of the member
* @param value value of the member
*/
- public void setMember(String name, Object value) {
+ public void setMember(final String name, final Object value) {
+ //empty
}
/**
@@ -145,7 +147,8 @@
* @param index index of the member slot
* @param value value of the member
*/
- public void setSlot(int index, Object value) {
+ public void setSlot(final int index, final Object value) {
+ //empty
}
// property and value iteration
--- a/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Thu Oct 10 16:16:20 2013 +0200
@@ -285,11 +285,10 @@
final URL url = ((URLReader)reader).getURL();
final Charset cs = ((URLReader)reader).getCharset();
return new Source(url.toString(), url, cs);
- } else {
- return new Source(getScriptName(ctxt), Source.readFully(reader));
}
- } catch (final IOException ioExp) {
- throw new ScriptException(ioExp);
+ return new Source(getScriptName(ctxt), Source.readFully(reader));
+ } catch (final IOException e) {
+ throw new ScriptException(e);
}
}
@@ -576,15 +575,14 @@
return new CompiledScript() {
@Override
public Object eval(final ScriptContext ctxt) throws ScriptException {
- final ScriptObject global = getNashornGlobalFrom(ctxt);
+ final ScriptObject globalObject = getNashornGlobalFrom(ctxt);
// Are we running the script in the correct global?
- if (func.getScope() == global) {
- return evalImpl(func, ctxt, global);
- } else {
- // ScriptContext with a different global. Compile again!
- // Note that we may still hit per-global compilation cache.
- return evalImpl(compileImpl(source, ctxt), ctxt, global);
+ if (func.getScope() == globalObject) {
+ return evalImpl(func, ctxt, globalObject);
}
+ // ScriptContext with a different global. Compile again!
+ // Note that we may still hit per-global compilation cache.
+ return evalImpl(compileImpl(source, ctxt), ctxt, globalObject);
}
@Override
public ScriptEngine getEngine() {
--- a/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java Thu Oct 10 16:16:20 2013 +0200
@@ -779,6 +779,10 @@
return value;
}
+ /**
+ * Get the array element type as Java format, e.g. [I
+ * @return array element type
+ */
public ArrayType getArrayType() {
if (elementType.isInteger()) {
return Type.INT_ARRAY;
--- a/nashorn/src/jdk/nashorn/internal/objects/Global.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/Global.java Thu Oct 10 16:16:20 2013 +0200
@@ -491,8 +491,8 @@
// GlobalObject interface implementation
@Override
- public boolean isOfContext(final Context context) {
- return this.context == context;
+ public boolean isOfContext(final Context ctxt) {
+ return this.context == ctxt;
}
@Override
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java Thu Oct 10 16:16:20 2013 +0200
@@ -30,6 +30,7 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
+
import jdk.nashorn.api.scripting.NashornException;
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Constructor;
@@ -135,11 +136,12 @@
* @param errorObj the error object
* @return undefined
*/
+ @SuppressWarnings("unused")
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
Global.checkObject(errorObj);
final ScriptObject sobj = (ScriptObject)errorObj;
- final ECMAException exp = new ECMAException(sobj, null);
+ new ECMAException(sobj, null); //constructor has side effects
sobj.delete("stack", false);
final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
--- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java Thu Oct 10 16:16:20 2013 +0200
@@ -249,7 +249,8 @@
private static final ClassLoader myLoader = Context.class.getClassLoader();
private static final StructureLoader sharedLoader;
- /*package-private*/ ClassLoader getSharedLoader() {
+ /*package-private*/ @SuppressWarnings("static-method")
+ ClassLoader getSharedLoader() {
return sharedLoader;
}
--- a/nashorn/src/jdk/nashorn/internal/runtime/DebugLogger.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/DebugLogger.java Thu Oct 10 16:16:20 2013 +0200
@@ -65,7 +65,17 @@
} else {
this.logger = Logging.getLogger(loggerName);
}
- this.isEnabled = logger.getLevel() != Level.OFF;
+ assert logger != null;
+ this.isEnabled = getLevel() != Level.OFF;
+ }
+
+ /**
+ * Do not currently support chaining this with parent logger. Logger level null
+ * means disabled
+ * @return level
+ */
+ private Level getLevel() {
+ return logger.getLevel() == null ? Level.OFF : logger.getLevel();
}
/**
@@ -126,7 +136,7 @@
* @return true if level is above the given one
*/
public boolean levelAbove(final Level level) {
- return logger.getLevel().intValue() > level.intValue();
+ return getLevel().intValue() > level.intValue();
}
/**
--- a/nashorn/src/jdk/nashorn/internal/runtime/GlobalObject.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/GlobalObject.java Thu Oct 10 16:16:20 2013 +0200
@@ -38,9 +38,10 @@
public interface GlobalObject {
/**
* Is this global of the given Context?
+ * @param ctxt the context
* @return true if this global belongs to the given Context
*/
- public boolean isOfContext(Context context);
+ public boolean isOfContext(final Context ctxt);
/**
* Does this global belong to a strict Context?
--- a/nashorn/src/jdk/nashorn/internal/runtime/ListAdapter.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ListAdapter.java Thu Oct 10 16:16:20 2013 +0200
@@ -119,10 +119,11 @@
});
}
+ /** wrapped object */
protected final Object obj;
// allow subclasses only in this package
- ListAdapter(Object obj) {
+ ListAdapter(final Object obj) {
this.obj = obj;
}
@@ -143,22 +144,32 @@
}
@Override
- public final Object get(int index) {
+ public final Object get(final int index) {
checkRange(index);
return getAt(index);
}
+ /**
+ * Get object at an index
+ * @param index index in list
+ * @return object
+ */
protected abstract Object getAt(final int index);
@Override
- public Object set(int index, Object element) {
+ public Object set(final int index, final Object element) {
checkRange(index);
final Object prevValue = getAt(index);
setAt(index, element);
return prevValue;
}
- protected abstract void setAt(int index, Object element);
+ /**
+ * Set object at an index
+ * @param index index in list
+ * @param element element
+ */
+ protected abstract void setAt(final int index, final Object element);
private void checkRange(int index) {
if(index < 0 || index >= size()) {
@@ -167,18 +178,18 @@
}
@Override
- public final void push(Object e) {
+ public final void push(final Object e) {
addFirst(e);
}
@Override
- public final boolean add(Object e) {
+ public final boolean add(final Object e) {
addLast(e);
return true;
}
@Override
- public final void addFirst(Object e) {
+ public final void addFirst(final Object e) {
try {
final InvokeByName unshiftInvoker = getUNSHIFT();
final Object fn = unshiftInvoker.getGetter().invokeExact(obj);
@@ -192,7 +203,7 @@
}
@Override
- public final void addLast(Object e) {
+ public final void addLast(final Object e) {
try {
final InvokeByName pushInvoker = getPUSH();
final Object fn = pushInvoker.getGetter().invokeExact(obj);
@@ -206,7 +217,7 @@
}
@Override
- public final void add(int index, Object e) {
+ public final void add(final int index, final Object e) {
try {
if(index < 0) {
throw invalidIndex(index);
@@ -225,35 +236,35 @@
throw invalidIndex(index);
}
}
- } catch(RuntimeException | Error ex) {
+ } catch(final RuntimeException | Error ex) {
throw ex;
- } catch(Throwable t) {
+ } catch(final Throwable t) {
throw new RuntimeException(t);
}
}
- private static void checkFunction(Object fn, InvokeByName invoke) {
+ private static void checkFunction(final Object fn, final InvokeByName invoke) {
if(!(Bootstrap.isCallable(fn))) {
throw new UnsupportedOperationException("The script object doesn't have a function named " + invoke.getName());
}
}
- private static IndexOutOfBoundsException invalidIndex(int index) {
+ private static IndexOutOfBoundsException invalidIndex(final int index) {
return new IndexOutOfBoundsException(String.valueOf(index));
}
@Override
- public final boolean offer(Object e) {
+ public final boolean offer(final Object e) {
return offerLast(e);
}
@Override
- public final boolean offerFirst(Object e) {
+ public final boolean offerFirst(final Object e) {
addFirst(e);
return true;
}
@Override
- public final boolean offerLast(Object e) {
+ public final boolean offerLast(final Object e) {
addLast(e);
return true;
}
@@ -287,7 +298,7 @@
}
@Override
- public final Object remove(int index) {
+ public final Object remove(final int index) {
if(index < 0) {
throw invalidIndex(index);
} else if (index == 0) {
@@ -333,11 +344,11 @@
}
@Override
- protected final void removeRange(int fromIndex, int toIndex) {
+ protected final void removeRange(final int fromIndex, final int toIndex) {
invokeSpliceRemove(fromIndex, toIndex - fromIndex);
}
- private void invokeSpliceRemove(int fromIndex, int count) {
+ private void invokeSpliceRemove(final int fromIndex, final int count) {
try {
final InvokeByName spliceRemoveInvoker = getSPLICE_REMOVE();
final Object fn = spliceRemoveInvoker.getGetter().invokeExact(obj);
@@ -419,16 +430,16 @@
}
@Override
- public final boolean removeFirstOccurrence(Object o) {
+ public final boolean removeFirstOccurrence(final Object o) {
return removeOccurrence(o, iterator());
}
@Override
- public final boolean removeLastOccurrence(Object o) {
+ public final boolean removeLastOccurrence(final Object o) {
return removeOccurrence(o, descendingIterator());
}
- private static boolean removeOccurrence(Object o, Iterator<Object> it) {
+ private static boolean removeOccurrence(final Object o, final Iterator<Object> it) {
while(it.hasNext()) {
final Object e = it.next();
if(o == null ? e == null : o.equals(e)) {
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptLoader.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptLoader.java Thu Oct 10 16:16:20 2013 +0200
@@ -64,6 +64,7 @@
return context.getSharedLoader().loadClass(name);
}
} catch (final ClassNotFoundException ignored) {
+ //ignored
}
// throw the original exception from here
--- a/nashorn/src/jdk/nashorn/internal/runtime/WithObject.java Thu Oct 10 14:43:22 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/WithObject.java Thu Oct 10 16:16:20 2013 +0200
@@ -316,6 +316,10 @@
return expression;
}
+ /**
+ * Get the parent scope for this {@code WithObject}
+ * @return the parent scope
+ */
public ScriptObject getParentScope() {
return getProto();
}