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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8-pool, 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b74
    • CPU:
      x86_64
    • OS:
      windows_7

      Backports

        Description

        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 ----------

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: