Wed, 16 Oct 2013 10:12:22 +0200
8026692: eval() throws NullPointerException with --compile-only
Reviewed-by: sundar, lagergren
1.1 --- a/src/jdk/nashorn/internal/codegen/CompilationPhase.java Tue Oct 15 13:14:04 2013 -0300 1.2 +++ b/src/jdk/nashorn/internal/codegen/CompilationPhase.java Wed Oct 16 10:12:22 2013 +0200 1.3 @@ -162,7 +162,7 @@ 1.4 LOWERING_PHASE(EnumSet.of(INITIALIZED, PARSED, CONSTANT_FOLDED)) { 1.5 @Override 1.6 FunctionNode transform(final Compiler compiler, final FunctionNode fn) { 1.7 - return (FunctionNode)fn.accept(new Lower(compiler)); 1.8 + return (FunctionNode)fn.accept(new Lower(compiler.getCodeInstaller())); 1.9 } 1.10 1.11 @Override
2.1 --- a/src/jdk/nashorn/internal/codegen/Lower.java Tue Oct 15 13:14:04 2013 -0300 2.2 +++ b/src/jdk/nashorn/internal/codegen/Lower.java Wed Oct 16 10:12:22 2013 +0200 2.3 @@ -68,6 +68,7 @@ 2.4 import jdk.nashorn.internal.ir.visitor.NodeVisitor; 2.5 import jdk.nashorn.internal.parser.Token; 2.6 import jdk.nashorn.internal.parser.TokenType; 2.7 +import jdk.nashorn.internal.runtime.CodeInstaller; 2.8 import jdk.nashorn.internal.runtime.DebugLogger; 2.9 import jdk.nashorn.internal.runtime.ScriptRuntime; 2.10 import jdk.nashorn.internal.runtime.Source; 2.11 @@ -86,13 +87,13 @@ 2.12 2.13 private static final DebugLogger LOG = new DebugLogger("lower"); 2.14 2.15 - // needed only to get unique eval id from code installer 2.16 - private final Compiler compiler; 2.17 + // needed only to get unique eval id 2.18 + private final CodeInstaller installer; 2.19 2.20 /** 2.21 * Constructor. 2.22 */ 2.23 - Lower(final Compiler compiler) { 2.24 + Lower(final CodeInstaller installer) { 2.25 super(new BlockLexicalContext() { 2.26 2.27 @Override 2.28 @@ -135,7 +136,7 @@ 2.29 return block.setIsTerminal(this, false); 2.30 } 2.31 }); 2.32 - this.compiler = compiler; 2.33 + this.installer = installer; 2.34 } 2.35 2.36 @Override 2.37 @@ -534,6 +535,8 @@ 2.38 private String evalLocation(final IdentNode node) { 2.39 final Source source = lc.getCurrentFunction().getSource(); 2.40 final int pos = node.position(); 2.41 + // Code installer is null when running with --compile-only, use 0 as id in that case 2.42 + final long id = installer == null ? 0 : installer.getUniqueEvalId(); 2.43 return new StringBuilder(). 2.44 append(source.getName()). 2.45 append('#'). 2.46 @@ -541,7 +544,7 @@ 2.47 append(':'). 2.48 append(source.getColumn(pos)). 2.49 append("<eval>@"). 2.50 - append(compiler.getCodeInstaller().getUniqueEvalId()). 2.51 + append(id). 2.52 toString(); 2.53 } 2.54
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/script/basic/JDK-8026692.js Wed Oct 16 10:12:22 2013 +0200 3.3 @@ -0,0 +1,32 @@ 3.4 +/* 3.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/** 3.28 + * JDK-8026692: eval() throws NullPointerException with --compile-only 3.29 + * 3.30 + * @test 3.31 + * @option --compile-only 3.32 + * @run 3.33 + */ 3.34 + 3.35 +eval("");