Details
-
Bug
-
Resolution: Fixed
-
P3
-
8
-
None
-
b100
-
generic
-
generic
-
Verified
Description
While testing another feature I missed a "}" to end object literal that had a multiple string in it.
File: test.js
print({
text: <<EOF
This is a multiple line
text inside a sting literal.
Run this with -scripting option.
EOF); // missing "}" to end literal
Instead of a compile error, compiler crashed :
jjs -scripting -doe test.js
String index out of range: 43
java.lang.StringIndexOutOfBoundsException: String index out of range: 43
at java.lang.String.charAt(String.java:651)
at jdk.nashorn.internal.runtime.ErrorManager.format(ErrorManager.java:116)
at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:243)
at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:229)
at jdk.nashorn.internal.parser.Parser.objectLiteral(Parser.java:1950)
at jdk.nashorn.internal.parser.Parser.primaryExpression(Parser.java:1790)
at jdk.nashorn.internal.parser.Parser.memberExpression(Parser.java:2294)
at jdk.nashorn.internal.parser.Parser.leftHandSideExpression(Parser.java:2154)
at jdk.nashorn.internal.parser.Parser.unaryExpression(Parser.java:2715)
at jdk.nashorn.internal.parser.Parser.assignmentExpression(Parser.java:2903)
at jdk.nashorn.internal.parser.Parser.argumentList(Parser.java:2371)
at jdk.nashorn.internal.parser.Parser.leftHandSideExpression(Parser.java:2157)
at jdk.nashorn.internal.parser.Parser.unaryExpression(Parser.java:2715)
at jdk.nashorn.internal.parser.Parser.expression(Parser.java:2845)
at jdk.nashorn.internal.parser.Parser.expressionStatement(Parser.java:993)
at jdk.nashorn.internal.parser.Parser.statement(Parser.java:830)
at jdk.nashorn.internal.parser.Parser.sourceElements(Parser.java:669)
at jdk.nashorn.internal.parser.Parser.program(Parser.java:607)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:192)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:167)
at jdk.nashorn.internal.runtime.Context.compile(Context.java:775)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:756)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:343)
at jdk.nashorn.tools.Shell.runScripts(Shell.java:308)
at jdk.nashorn.tools.Shell.run(Shell.java:178)
at jdk.nashorn.tools.Shell.main(Shell.java:142)
at jdk.nashorn.tools.Shell.main(Shell.java:121)
On inspection of AbstractParser/Parser code, it is clear that the parser does not sync 'last line' and 'last line position' with Lexer. This is not a problem when there is no multiple line string literals. But with multiple line string literals, Lexer knows the correct last line and last line position. Parser has old last line info found at the start of multiline string literal.
Another test that shows line number sync issue:
print({
text: <<EOF
This is a multiple line
text inside a sting literal.
Run this with -scripting option.
EOF}); var x++;
File: test.js
print({
text: <<EOF
This is a multiple line
text inside a sting literal.
Run this with -scripting option.
EOF); // missing "}" to end literal
Instead of a compile error, compiler crashed :
jjs -scripting -doe test.js
String index out of range: 43
java.lang.StringIndexOutOfBoundsException: String index out of range: 43
at java.lang.String.charAt(String.java:651)
at jdk.nashorn.internal.runtime.ErrorManager.format(ErrorManager.java:116)
at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:243)
at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:229)
at jdk.nashorn.internal.parser.Parser.objectLiteral(Parser.java:1950)
at jdk.nashorn.internal.parser.Parser.primaryExpression(Parser.java:1790)
at jdk.nashorn.internal.parser.Parser.memberExpression(Parser.java:2294)
at jdk.nashorn.internal.parser.Parser.leftHandSideExpression(Parser.java:2154)
at jdk.nashorn.internal.parser.Parser.unaryExpression(Parser.java:2715)
at jdk.nashorn.internal.parser.Parser.assignmentExpression(Parser.java:2903)
at jdk.nashorn.internal.parser.Parser.argumentList(Parser.java:2371)
at jdk.nashorn.internal.parser.Parser.leftHandSideExpression(Parser.java:2157)
at jdk.nashorn.internal.parser.Parser.unaryExpression(Parser.java:2715)
at jdk.nashorn.internal.parser.Parser.expression(Parser.java:2845)
at jdk.nashorn.internal.parser.Parser.expressionStatement(Parser.java:993)
at jdk.nashorn.internal.parser.Parser.statement(Parser.java:830)
at jdk.nashorn.internal.parser.Parser.sourceElements(Parser.java:669)
at jdk.nashorn.internal.parser.Parser.program(Parser.java:607)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:192)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:167)
at jdk.nashorn.internal.runtime.Context.compile(Context.java:775)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:756)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:343)
at jdk.nashorn.tools.Shell.runScripts(Shell.java:308)
at jdk.nashorn.tools.Shell.run(Shell.java:178)
at jdk.nashorn.tools.Shell.main(Shell.java:142)
at jdk.nashorn.tools.Shell.main(Shell.java:121)
On inspection of AbstractParser/Parser code, it is clear that the parser does not sync 'last line' and 'last line position' with Lexer. This is not a problem when there is no multiple line string literals. But with multiple line string literals, Lexer knows the correct last line and last line position. Parser has old last line info found at the start of multiline string literal.
Another test that shows line number sync issue:
print({
text: <<EOF
This is a multiple line
text inside a sting literal.
Run this with -scripting option.
EOF}); var x++;