Javascript expression causing rhino to crash with Exception in thread "main" java.lang.IllegalArgumentException Unmatched braces in the pattern

UNCONFIRMED
Unassigned

Status

Rhino
Core
UNCONFIRMED
5 years ago
4 years ago

People

(Reporter: Raphaël Jakse, Unassigned)

Tracking

Details

(Reporter)

Description

5 years ago
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0 (Beta/Release)
Build ID: 20130917154415

Steps to reproduce:

I tried to eval "function() true" expression in Rhino 1.7R4-2 on Ubuntu 13.10.

var abbreviatedFunctionSupported = false;
try {
  abbreviatedFunctionSupported = eval("(function() true)()");
}
catch(e) {
   // abbreviated functions not supported
}


Actual results:

Rhino crashed with the following Java exception:
Exception in thread "main" java.lang.IllegalArgumentException Unmatched braces in the pattern.

Trying to execute the following malformed javascript code in the rhino interpreter also triggers the crash:
function() 

Trace:
Exception in thread "main" java.lang.IllegalArgumentException: Unmatched braces in the pattern.
        at java.text.MessageFormat.applyPattern(MessageFormat.java:508)
        at java.text.MessageFormat.<init>(MessageFormat.java:363)
        at org.mozilla.javascript.ScriptRuntime$DefaultMessageProvider.getMessage(ScriptRuntime.java:3656)
        at org.mozilla.javascript.ScriptRuntime.getMessage(ScriptRuntime.java:3625)
        at org.mozilla.javascript.ScriptRuntime.getMessage0(ScriptRuntime.java:3573)
        at org.mozilla.javascript.Parser.lookupMessage(Parser.java:197)
        at org.mozilla.javascript.Parser.addError(Parser.java:177)
        at org.mozilla.javascript.Parser.addError(Parser.java:166)
        at org.mozilla.javascript.Parser.reportError(Parser.java:223)
        at org.mozilla.javascript.Parser.reportError(Parser.java:210)
        at org.mozilla.javascript.Parser.reportError(Parser.java:203)
        at org.mozilla.javascript.Parser.parseFunctionBody(Parser.java:597)
        at org.mozilla.javascript.Parser.function(Parser.java:795)
        at org.mozilla.javascript.Parser.primaryExpr(Parser.java:2761)
        at org.mozilla.javascript.Parser.memberExpr(Parser.java:2406)
        at org.mozilla.javascript.Parser.unaryExpr(Parser.java:2304)
        at org.mozilla.javascript.Parser.mulExpr(Parser.java:2229)
        at org.mozilla.javascript.Parser.addExpr(Parser.java:2213)
        at org.mozilla.javascript.Parser.shiftExpr(Parser.java:2194)
        at org.mozilla.javascript.Parser.relExpr(Parser.java:2169)
        at org.mozilla.javascript.Parser.eqExpr(Parser.java:2141)
        at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:2130)
        at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:2119)
        at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:2108)
        at org.mozilla.javascript.Parser.andExpr(Parser.java:2097)
        at org.mozilla.javascript.Parser.orExpr(Parser.java:2086)
        at org.mozilla.javascript.Parser.condExpr(Parser.java:2062)
        at org.mozilla.javascript.Parser.assignExpr(Parser.java:2033)
        at org.mozilla.javascript.Parser.expr(Parser.java:2012)
        at org.mozilla.javascript.Parser.parenExpr(Parser.java:2839)
        at org.mozilla.javascript.Parser.primaryExpr(Parser.java:2773)
        at org.mozilla.javascript.Parser.memberExpr(Parser.java:2406)
        at org.mozilla.javascript.Parser.unaryExpr(Parser.java:2304)
        at org.mozilla.javascript.Parser.mulExpr(Parser.java:2229)
        at org.mozilla.javascript.Parser.addExpr(Parser.java:2213)
        at org.mozilla.javascript.Parser.shiftExpr(Parser.java:2194)
        at org.mozilla.javascript.Parser.relExpr(Parser.java:2169)
        at org.mozilla.javascript.Parser.eqExpr(Parser.java:2141)
        at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:2130)
        at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:2119)
        at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:2108)
        at org.mozilla.javascript.Parser.andExpr(Parser.java:2097)
        at org.mozilla.javascript.Parser.orExpr(Parser.java:2086)
        at org.mozilla.javascript.Parser.condExpr(Parser.java:2062)
        at org.mozilla.javascript.Parser.assignExpr(Parser.java:2033)
        at org.mozilla.javascript.Parser.expr(Parser.java:2012)
        at org.mozilla.javascript.Parser.statementHelper(Parser.java:1039)
        at org.mozilla.javascript.Parser.statement(Parser.java:901)
        at org.mozilla.javascript.Parser.parse(Parser.java:540)
        at org.mozilla.javascript.Parser.parse(Parser.java:478)
        at org.mozilla.javascript.Context.compileImpl(Context.java:2348)
        at org.mozilla.javascript.Context.compileString(Context.java:1335)
        at org.mozilla.javascript.ScriptRuntime.evalSpecial(ScriptRuntime.java:2504)
        at org.mozilla.javascript.ScriptRuntime.callSpecial(ScriptRuntime.java:2360)
        at org.mozilla.javascript.optimizer.OptRuntime.callSpecial(OptRuntime.java:131)
        at org.mozilla.javascript.gen._stdin__2._c_script_0(Unknown Source)
        at org.mozilla.javascript.gen._stdin__2.call(Unknown Source)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
        at org.mozilla.javascript.gen._stdin__2.call(Unknown Source)
        at org.mozilla.javascript.gen._stdin__2.exec(Unknown Source)
        at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:502)
        at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:178)
        at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:102)
        at org.mozilla.javascript.Context.call(Context.java:489)
        at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:504)
        at org.mozilla.javascript.tools.shell.Main.exec(Main.java:160)
        at org.mozilla.javascript.tools.shell.Main.main(Main.java:138)



Expected results:

Rhino should not have crashed. At least, the exception should have been handled by the try/catch statement.

Comment 1

4 years ago
Hi,

I encountered the same issue, and tracked down the problem to formatting issues in the french translation of the parser's messages. Given your first name, I guess you may have using Rhino with a french locale too.

A temporary workaround is to force the JVM to speak in english.

To fix the bug completely, here is a commit that will do it (and fix other similar errors related to escaping):
https://github.com/tlecomte/RhinoPlugin/commit/3801f9a761aff86bab72fccbea19cdd61c011997
(Reporter)

Comment 2

4 years ago
Hello,

Indeed, I used Rhino with the French locale and when I lanch Rhino with the LC_ALL environment variable set to 'C', I get an error message from Rhino instead of the crash.
You need to log in before you can comment on or make changes to this bug.