8026250: Logging nullpointer bugfix and javadoc warnings

Thu, 10 Oct 2013 16:16:20 +0200

author
lagergren
date
Thu, 10 Oct 2013 16:16:20 +0200
changeset 610
ed3da7a574a0
parent 609
34f7a699cdef
child 611
a781ea074521

8026250: Logging nullpointer bugfix and javadoc warnings
Reviewed-by: hannesw, jlaskey, sundar

src/jdk/nashorn/api/scripting/JSObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/api/scripting/NashornScriptEngine.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/LiteralNode.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Context.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/DebugLogger.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/GlobalObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ListAdapter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptLoader.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/WithObject.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/api/scripting/JSObject.java	Thu Oct 10 14:43:22 2013 +0200
     1.2 +++ b/src/jdk/nashorn/api/scripting/JSObject.java	Thu Oct 10 16:16:20 2013 +0200
     1.3 @@ -46,7 +46,7 @@
     1.4       * @param args arguments to method
     1.5       * @return result of call
     1.6       */
     1.7 -    public Object call(Object thiz, Object... args) {
     1.8 +    public Object call(final Object thiz, final Object... args) {
     1.9          throw new UnsupportedOperationException("call");
    1.10      }
    1.11  
    1.12 @@ -57,7 +57,7 @@
    1.13       * @param args arguments to method
    1.14       * @return result of constructor call
    1.15       */
    1.16 -    public Object newObject(Object... args) {
    1.17 +    public Object newObject(final Object... args) {
    1.18          throw new UnsupportedOperationException("newObject");
    1.19      }
    1.20  
    1.21 @@ -67,7 +67,7 @@
    1.22       * @param s JavaScript expression to evaluate
    1.23       * @return evaluation result
    1.24       */
    1.25 -    public Object eval(String s) {
    1.26 +    public Object eval(final String s) {
    1.27          throw new UnsupportedOperationException("eval");
    1.28      }
    1.29  
    1.30 @@ -78,7 +78,7 @@
    1.31       * @param args arguments to be passed to the member function
    1.32       * @return result of call
    1.33       */
    1.34 -    public Object callMember(String name, Object... args) {
    1.35 +    public Object callMember(final String name, final Object... args) {
    1.36          throw new UnsupportedOperationException("call");
    1.37      }
    1.38  
    1.39 @@ -88,7 +88,7 @@
    1.40       * @param name of member
    1.41       * @return member
    1.42       */
    1.43 -    public Object getMember(String name) {
    1.44 +    public Object getMember(final String name) {
    1.45          return null;
    1.46      }
    1.47  
    1.48 @@ -98,7 +98,7 @@
    1.49       * @param index index slot to retrieve
    1.50       * @return member
    1.51       */
    1.52 -    public Object getSlot(int index) {
    1.53 +    public Object getSlot(final int index) {
    1.54          return null;
    1.55      }
    1.56  
    1.57 @@ -108,7 +108,7 @@
    1.58       * @param name name of member
    1.59       * @return true if this object has a member of the given name
    1.60       */
    1.61 -    public boolean hasMember(String name) {
    1.62 +    public boolean hasMember(final String name) {
    1.63          return false;
    1.64      }
    1.65  
    1.66 @@ -118,7 +118,7 @@
    1.67       * @param slot index to check
    1.68       * @return true if this object has a slot
    1.69       */
    1.70 -    public boolean hasSlot(int slot) {
    1.71 +    public boolean hasSlot(final int slot) {
    1.72          return false;
    1.73      }
    1.74  
    1.75 @@ -127,7 +127,8 @@
    1.76       *
    1.77       * @param name name of the member
    1.78       */
    1.79 -    public void removeMember(String name) {
    1.80 +    public void removeMember(final String name) {
    1.81 +        //empty
    1.82      }
    1.83  
    1.84      /**
    1.85 @@ -136,7 +137,8 @@
    1.86       * @param name  name of the member
    1.87       * @param value value of the member
    1.88       */
    1.89 -    public void setMember(String name, Object value) {
    1.90 +    public void setMember(final String name, final Object value) {
    1.91 +        //empty
    1.92      }
    1.93  
    1.94      /**
    1.95 @@ -145,7 +147,8 @@
    1.96       * @param index index of the member slot
    1.97       * @param value value of the member
    1.98       */
    1.99 -    public void setSlot(int index, Object value) {
   1.100 +    public void setSlot(final int index, final Object value) {
   1.101 +        //empty
   1.102      }
   1.103  
   1.104      // property and value iteration
     2.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Thu Oct 10 14:43:22 2013 +0200
     2.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Thu Oct 10 16:16:20 2013 +0200
     2.3 @@ -285,11 +285,10 @@
     2.4                  final URL url = ((URLReader)reader).getURL();
     2.5                  final Charset cs = ((URLReader)reader).getCharset();
     2.6                  return new Source(url.toString(), url, cs);
     2.7 -            } else {
     2.8 -                return new Source(getScriptName(ctxt), Source.readFully(reader));
     2.9              }
    2.10 -        } catch (final IOException ioExp) {
    2.11 -            throw new ScriptException(ioExp);
    2.12 +            return new Source(getScriptName(ctxt), Source.readFully(reader));
    2.13 +        } catch (final IOException e) {
    2.14 +            throw new ScriptException(e);
    2.15          }
    2.16      }
    2.17  
    2.18 @@ -576,15 +575,14 @@
    2.19          return new CompiledScript() {
    2.20              @Override
    2.21              public Object eval(final ScriptContext ctxt) throws ScriptException {
    2.22 -                final ScriptObject global = getNashornGlobalFrom(ctxt);
    2.23 +                final ScriptObject globalObject = getNashornGlobalFrom(ctxt);
    2.24                  // Are we running the script in the correct global?
    2.25 -                if (func.getScope() == global) {
    2.26 -                    return evalImpl(func, ctxt, global);
    2.27 -                } else {
    2.28 -                    // ScriptContext with a different global. Compile again!
    2.29 -                    // Note that we may still hit per-global compilation cache.
    2.30 -                    return evalImpl(compileImpl(source, ctxt), ctxt, global);
    2.31 +                if (func.getScope() == globalObject) {
    2.32 +                    return evalImpl(func, ctxt, globalObject);
    2.33                  }
    2.34 +                // ScriptContext with a different global. Compile again!
    2.35 +                // Note that we may still hit per-global compilation cache.
    2.36 +                return evalImpl(compileImpl(source, ctxt), ctxt, globalObject);
    2.37              }
    2.38              @Override
    2.39              public ScriptEngine getEngine() {
     3.1 --- a/src/jdk/nashorn/internal/ir/LiteralNode.java	Thu Oct 10 14:43:22 2013 +0200
     3.2 +++ b/src/jdk/nashorn/internal/ir/LiteralNode.java	Thu Oct 10 16:16:20 2013 +0200
     3.3 @@ -779,6 +779,10 @@
     3.4              return value;
     3.5          }
     3.6  
     3.7 +        /**
     3.8 +         * Get the array element type as Java format, e.g. [I
     3.9 +         * @return array element type
    3.10 +         */
    3.11          public ArrayType getArrayType() {
    3.12              if (elementType.isInteger()) {
    3.13                  return Type.INT_ARRAY;
     4.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Thu Oct 10 14:43:22 2013 +0200
     4.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Thu Oct 10 16:16:20 2013 +0200
     4.3 @@ -491,8 +491,8 @@
     4.4      // GlobalObject interface implementation
     4.5  
     4.6      @Override
     4.7 -    public boolean isOfContext(final Context context) {
     4.8 -        return this.context == context;
     4.9 +    public boolean isOfContext(final Context ctxt) {
    4.10 +        return this.context == ctxt;
    4.11      }
    4.12  
    4.13      @Override
     5.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java	Thu Oct 10 14:43:22 2013 +0200
     5.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java	Thu Oct 10 16:16:20 2013 +0200
     5.3 @@ -30,6 +30,7 @@
     5.4  
     5.5  import java.lang.invoke.MethodHandle;
     5.6  import java.lang.invoke.MethodHandles;
     5.7 +
     5.8  import jdk.nashorn.api.scripting.NashornException;
     5.9  import jdk.nashorn.internal.objects.annotations.Attribute;
    5.10  import jdk.nashorn.internal.objects.annotations.Constructor;
    5.11 @@ -135,11 +136,12 @@
    5.12       * @param errorObj the error object
    5.13       * @return undefined
    5.14       */
    5.15 +    @SuppressWarnings("unused")
    5.16      @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
    5.17      public static Object captureStackTrace(final Object self, final Object errorObj) {
    5.18          Global.checkObject(errorObj);
    5.19          final ScriptObject sobj = (ScriptObject)errorObj;
    5.20 -        final ECMAException exp = new ECMAException(sobj, null);
    5.21 +        new ECMAException(sobj, null); //constructor has side effects
    5.22          sobj.delete("stack", false);
    5.23          final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
    5.24          final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
     6.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Thu Oct 10 14:43:22 2013 +0200
     6.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Thu Oct 10 16:16:20 2013 +0200
     6.3 @@ -249,7 +249,8 @@
     6.4      private static final ClassLoader myLoader = Context.class.getClassLoader();
     6.5      private static final StructureLoader sharedLoader;
     6.6  
     6.7 -    /*package-private*/ ClassLoader getSharedLoader() {
     6.8 +    /*package-private*/ @SuppressWarnings("static-method")
     6.9 +    ClassLoader getSharedLoader() {
    6.10          return sharedLoader;
    6.11      }
    6.12  
     7.1 --- a/src/jdk/nashorn/internal/runtime/DebugLogger.java	Thu Oct 10 14:43:22 2013 +0200
     7.2 +++ b/src/jdk/nashorn/internal/runtime/DebugLogger.java	Thu Oct 10 16:16:20 2013 +0200
     7.3 @@ -65,7 +65,17 @@
     7.4          } else {
     7.5              this.logger = Logging.getLogger(loggerName);
     7.6          }
     7.7 -        this.isEnabled = logger.getLevel() != Level.OFF;
     7.8 +        assert logger != null;
     7.9 +        this.isEnabled = getLevel() != Level.OFF;
    7.10 +    }
    7.11 +
    7.12 +    /**
    7.13 +     * Do not currently support chaining this with parent logger. Logger level null
    7.14 +     * means disabled
    7.15 +     * @return level
    7.16 +     */
    7.17 +    private Level getLevel() {
    7.18 +        return logger.getLevel() == null ? Level.OFF : logger.getLevel();
    7.19      }
    7.20  
    7.21      /**
    7.22 @@ -126,7 +136,7 @@
    7.23       * @return true if level is above the given one
    7.24       */
    7.25      public boolean levelAbove(final Level level) {
    7.26 -        return logger.getLevel().intValue() > level.intValue();
    7.27 +        return getLevel().intValue() > level.intValue();
    7.28      }
    7.29  
    7.30      /**
     8.1 --- a/src/jdk/nashorn/internal/runtime/GlobalObject.java	Thu Oct 10 14:43:22 2013 +0200
     8.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalObject.java	Thu Oct 10 16:16:20 2013 +0200
     8.3 @@ -38,9 +38,10 @@
     8.4  public interface GlobalObject {
     8.5      /**
     8.6       * Is this global of the given Context?
     8.7 +     * @param ctxt the context
     8.8       * @return true if this global belongs to the given Context
     8.9       */
    8.10 -    public boolean isOfContext(Context context);
    8.11 +    public boolean isOfContext(final Context ctxt);
    8.12  
    8.13      /**
    8.14       * Does this global belong to a strict Context?
     9.1 --- a/src/jdk/nashorn/internal/runtime/ListAdapter.java	Thu Oct 10 14:43:22 2013 +0200
     9.2 +++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java	Thu Oct 10 16:16:20 2013 +0200
     9.3 @@ -119,10 +119,11 @@
     9.4                  });
     9.5      }
     9.6  
     9.7 +    /** wrapped object */
     9.8      protected final Object obj;
     9.9  
    9.10      // allow subclasses only in this package
    9.11 -    ListAdapter(Object obj) {
    9.12 +    ListAdapter(final Object obj) {
    9.13          this.obj = obj;
    9.14      }
    9.15  
    9.16 @@ -143,22 +144,32 @@
    9.17      }
    9.18  
    9.19      @Override
    9.20 -    public final Object get(int index) {
    9.21 +    public final Object get(final int index) {
    9.22          checkRange(index);
    9.23          return getAt(index);
    9.24      }
    9.25  
    9.26 +    /**
    9.27 +     * Get object at an index
    9.28 +     * @param index index in list
    9.29 +     * @return object
    9.30 +     */
    9.31      protected abstract Object getAt(final int index);
    9.32  
    9.33      @Override
    9.34 -    public Object set(int index, Object element) {
    9.35 +    public Object set(final int index, final Object element) {
    9.36          checkRange(index);
    9.37          final Object prevValue = getAt(index);
    9.38          setAt(index, element);
    9.39          return prevValue;
    9.40      }
    9.41  
    9.42 -    protected abstract void setAt(int index, Object element);
    9.43 +    /**
    9.44 +     * Set object at an index
    9.45 +     * @param index   index in list
    9.46 +     * @param element element
    9.47 +     */
    9.48 +    protected abstract void setAt(final int index, final Object element);
    9.49  
    9.50      private void checkRange(int index) {
    9.51          if(index < 0 || index >= size()) {
    9.52 @@ -167,18 +178,18 @@
    9.53      }
    9.54  
    9.55      @Override
    9.56 -    public final void push(Object e) {
    9.57 +    public final void push(final Object e) {
    9.58          addFirst(e);
    9.59      }
    9.60  
    9.61      @Override
    9.62 -    public final boolean add(Object e) {
    9.63 +    public final boolean add(final Object e) {
    9.64          addLast(e);
    9.65          return true;
    9.66      }
    9.67  
    9.68      @Override
    9.69 -    public final void addFirst(Object e) {
    9.70 +    public final void addFirst(final Object e) {
    9.71          try {
    9.72              final InvokeByName unshiftInvoker = getUNSHIFT();
    9.73              final Object fn = unshiftInvoker.getGetter().invokeExact(obj);
    9.74 @@ -192,7 +203,7 @@
    9.75      }
    9.76  
    9.77      @Override
    9.78 -    public final void addLast(Object e) {
    9.79 +    public final void addLast(final Object e) {
    9.80          try {
    9.81              final InvokeByName pushInvoker = getPUSH();
    9.82              final Object fn = pushInvoker.getGetter().invokeExact(obj);
    9.83 @@ -206,7 +217,7 @@
    9.84      }
    9.85  
    9.86      @Override
    9.87 -    public final void add(int index, Object e) {
    9.88 +    public final void add(final int index, final Object e) {
    9.89          try {
    9.90              if(index < 0) {
    9.91                  throw invalidIndex(index);
    9.92 @@ -225,35 +236,35 @@
    9.93                      throw invalidIndex(index);
    9.94                  }
    9.95              }
    9.96 -        } catch(RuntimeException | Error ex) {
    9.97 +        } catch(final RuntimeException | Error ex) {
    9.98              throw ex;
    9.99 -        } catch(Throwable t) {
   9.100 +        } catch(final Throwable t) {
   9.101              throw new RuntimeException(t);
   9.102          }
   9.103      }
   9.104 -    private static void checkFunction(Object fn, InvokeByName invoke) {
   9.105 +    private static void checkFunction(final Object fn, final InvokeByName invoke) {
   9.106          if(!(Bootstrap.isCallable(fn))) {
   9.107              throw new UnsupportedOperationException("The script object doesn't have a function named " + invoke.getName());
   9.108          }
   9.109      }
   9.110  
   9.111 -    private static IndexOutOfBoundsException invalidIndex(int index) {
   9.112 +    private static IndexOutOfBoundsException invalidIndex(final int index) {
   9.113          return new IndexOutOfBoundsException(String.valueOf(index));
   9.114      }
   9.115  
   9.116      @Override
   9.117 -    public final boolean offer(Object e) {
   9.118 +    public final boolean offer(final Object e) {
   9.119          return offerLast(e);
   9.120      }
   9.121  
   9.122      @Override
   9.123 -    public final boolean offerFirst(Object e) {
   9.124 +    public final boolean offerFirst(final Object e) {
   9.125          addFirst(e);
   9.126          return true;
   9.127      }
   9.128  
   9.129      @Override
   9.130 -    public final boolean offerLast(Object e) {
   9.131 +    public final boolean offerLast(final Object e) {
   9.132          addLast(e);
   9.133          return true;
   9.134      }
   9.135 @@ -287,7 +298,7 @@
   9.136      }
   9.137  
   9.138      @Override
   9.139 -    public final Object remove(int index) {
   9.140 +    public final Object remove(final int index) {
   9.141          if(index < 0) {
   9.142              throw invalidIndex(index);
   9.143          } else if (index == 0) {
   9.144 @@ -333,11 +344,11 @@
   9.145      }
   9.146  
   9.147      @Override
   9.148 -    protected final void removeRange(int fromIndex, int toIndex) {
   9.149 +    protected final void removeRange(final int fromIndex, final int toIndex) {
   9.150          invokeSpliceRemove(fromIndex, toIndex - fromIndex);
   9.151      }
   9.152  
   9.153 -    private void invokeSpliceRemove(int fromIndex, int count) {
   9.154 +    private void invokeSpliceRemove(final int fromIndex, final int count) {
   9.155          try {
   9.156              final InvokeByName spliceRemoveInvoker = getSPLICE_REMOVE();
   9.157              final Object fn = spliceRemoveInvoker.getGetter().invokeExact(obj);
   9.158 @@ -419,16 +430,16 @@
   9.159      }
   9.160  
   9.161      @Override
   9.162 -    public final boolean removeFirstOccurrence(Object o) {
   9.163 +    public final boolean removeFirstOccurrence(final Object o) {
   9.164          return removeOccurrence(o, iterator());
   9.165      }
   9.166  
   9.167      @Override
   9.168 -    public final boolean removeLastOccurrence(Object o) {
   9.169 +    public final boolean removeLastOccurrence(final Object o) {
   9.170          return removeOccurrence(o, descendingIterator());
   9.171      }
   9.172  
   9.173 -    private static boolean removeOccurrence(Object o, Iterator<Object> it) {
   9.174 +    private static boolean removeOccurrence(final Object o, final Iterator<Object> it) {
   9.175          while(it.hasNext()) {
   9.176              final Object e = it.next();
   9.177              if(o == null ? e == null : o.equals(e)) {
    10.1 --- a/src/jdk/nashorn/internal/runtime/ScriptLoader.java	Thu Oct 10 14:43:22 2013 +0200
    10.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptLoader.java	Thu Oct 10 16:16:20 2013 +0200
    10.3 @@ -64,6 +64,7 @@
    10.4                      return context.getSharedLoader().loadClass(name);
    10.5                  }
    10.6              } catch (final ClassNotFoundException ignored) {
    10.7 +                //ignored
    10.8              }
    10.9  
   10.10              // throw the original exception from here
    11.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java	Thu Oct 10 14:43:22 2013 +0200
    11.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java	Thu Oct 10 16:16:20 2013 +0200
    11.3 @@ -316,6 +316,10 @@
    11.4          return expression;
    11.5      }
    11.6  
    11.7 +    /**
    11.8 +     * Get the parent scope for this {@code WithObject}
    11.9 +     * @return the parent scope
   11.10 +     */
   11.11      public ScriptObject getParentScope() {
   11.12          return getProto();
   11.13      }

mercurial