8058561: NPE in LocalVariableTypesCalculator

Reviewed-by: lagergren, sundar
This commit is contained in:
Attila Szegedi 2014-09-22 14:46:04 +02:00
parent 62f4b355b5
commit 00019f9c03
2 changed files with 53 additions and 1 deletions

View File

@ -558,7 +558,7 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
// 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 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
@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 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
@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 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
@Override
public boolean enterVarNode(final VarNode varNode) {
if (!reachable) {
return false;
}
final Expression init = varNode.getInit();
if(init != null) {
init.accept(this);

View File

@ -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;
}