Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8131039

after adding a function property to Object.prototype, JSON.parse with reviver function goes into infinite loop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8-pool, 9
    • core-libs
    • b74
    • x86_64
    • windows_7

        FULL PRODUCT VERSION :
        java version "1.8.0_45"
        Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
        Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Windows -7

        A DESCRIPTION OF THE PROBLEM :
        public static void main(String[] args) throws ScriptException {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
        engine.eval("Object.prototype.merge = function(obj2){ return this; }");
        engine.eval("function nothingTodo(k, v) {return v}");
        engine.eval("JSON.parse('{\"name\" : \"jack\"}')");
                        // ^^^^^^^^^^^^ THAT IS OK
        engine.eval("JSON.parse('{\"name\" : \"jack\"}', nothingTodo)");
                        // ^^^^^^^^^^^^ DEAD LOOP
        }


        Exception in thread "main" java.lang.StackOverflowError
        at jdk.nashorn.internal.runtime.PropertyHashMap.find(PropertyHashMap.java:275)
        at jdk.nashorn.internal.runtime.PropertyMap.findProperty(PropertyMap.java:552)
        at jdk.nashorn.internal.runtime.ScriptObject.findProperty(ScriptObject.java:814)
        at jdk.nashorn.internal.runtime.ScriptObject.findProperty(ScriptObject.java:823)
        at jdk.nashorn.internal.runtime.ScriptObject.findProperty(ScriptObject.java:790)
        at jdk.nashorn.internal.runtime.ScriptObject.get(ScriptObject.java:3000)
        at jdk.nashorn.internal.runtime.ScriptObject.get(ScriptObject.java:3020)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:113)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)


        REGRESSION. Last worked in version 8u45


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "main" java.lang.StackOverflowError
        at jdk.nashorn.internal.runtime.PropertyHashMap.find(PropertyHashMap.java:275)
        at jdk.nashorn.internal.runtime.PropertyMap.findProperty(PropertyMap.java:552)
        at jdk.nashorn.internal.runtime.ScriptObject.findProperty(ScriptObject.java:814)
        at jdk.nashorn.internal.runtime.ScriptObject.findProperty(ScriptObject.java:823)
        at jdk.nashorn.internal.runtime.ScriptObject.findProperty(ScriptObject.java:790)
        at jdk.nashorn.internal.runtime.ScriptObject.get(ScriptObject.java:3000)
        at jdk.nashorn.internal.runtime.ScriptObject.get(ScriptObject.java:3020)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:113)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)
        at jdk.nashorn.internal.runtime.JSONFunctions.walk(JSONFunctions.java:120)

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.script.ScriptEngine;
        import javax.script.ScriptEngineManager;
        import javax.script.ScriptException;

        public class Look {
        public static void main(String[] args) throws ScriptException {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
        engine.eval("Object.prototype.merge = function(obj2){ return this; }");
        engine.eval("function nothingTodo(k, v) {return v}");
        engine.eval("JSON.parse('{\"name\" : \"jack\"}')");
        engine.eval("JSON.parse('{\"name\" : \"jack\"}', nothingTodo)");
        }
        }

        ---------- END SOURCE ----------

              sundar Sundararajan Athijegannathan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: