changeset 978:73c31575a0c0

8058561: NPE in LocalVariableTypesCalculator Reviewed-by: lagergren, sundar
author attila
date Mon, 22 Sep 2014 14:46:04 +0200
parents acb17eade642
children 9ee8fd4a7266
files src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java test/script/basic/JDK-8058561.js
diffstat 2 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java	Fri Sep 19 13:13:20 2014 +0200
+++ b/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java	Mon Sep 22 14:46:04 2014 +0200
@@ -558,7 +558,7 @@
                     // of the compilation that the object being iterated over must use strings for property
                     // names (e.g., it is a native JS object or array), then we'll not bother trying to treat
                     // the property names optimistically.
-                    !forNode.isForEach() && compiler.hasStringPropertyIterator(iterable.getExpression()));
+                    !compiler.useOptimisticTypes() || (!forNode.isForEach() && compiler.hasStringPropertyIterator(iterable.getExpression())));
         } else {
             if(init != null) {
                 init.accept(this);
@@ -686,6 +686,10 @@
 
     @Override
     public boolean enterReturnNode(final ReturnNode returnNode) {
+        if(!reachable) {
+            return false;
+        }
+
         final Expression returnExpr = returnNode.getExpression();
         final Type returnExprType;
         if(returnExpr != null) {
@@ -701,6 +705,9 @@
 
     @Override
     public boolean enterSplitNode(final SplitNode splitNode) {
+        if(!reachable) {
+            return false;
+        }
         // Need to visit inside of split nodes. While it's true that they don't have local variables, we need to visit
         // breaks, continues, and returns in them.
         if(topSplit == null) {
@@ -950,6 +957,9 @@
 
     @Override
     public boolean enterVarNode(final VarNode varNode) {
+        if (!reachable) {
+            return false;
+        }
         final Expression init = varNode.getInit();
         if(init != null) {
             init.accept(this);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8058561.js	Mon Sep 22 14:46:04 2014 +0200
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8058561: NPE in LocalVariableTypesCalculator
+ *
+ * @test
+ * @run
+ * @option --lazy-compilation=false
+ */
+
+// Just attempting to compile this caused the NPE
+function func(x, y) {
+  while(true) {
+     switch (y[0]) {
+       case "bar": 
+           x = 'xxx';
+           break;
+     }
+  }
+  return x;
+}