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

Calling a @FunctionalInterface from JS leaks internal objects

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8, 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b47
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        When calling from JS to Java, Nashorn filters internal implementation objects; ConsString is converted to String and ScriptObject to ScriptObjectMirror before being passed on. Unfortunately, calling a @FunctionalInterface object is implemented as a separate code path, and this filtering is missing there.



        import java.util.function.Function;
        import javax.script.ScriptEngine;
        import javax.script.ScriptException;
        import jdk.nashorn.api.scripting.NashornScriptEngineFactory;

        public class CS {
            public static void main(String[] args) throws ScriptException {
                ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();
                engine.put("f", new Function<String, String>() {
                    @Override
                    public String apply(String t) {
                        return t;
                    }
                });
                engine.eval("var x = 'a'; x += 'b'; f(x)");
            }
        }

        throws java.lang.ClassCastException: jdk.nashorn.internal.runtime.ConsString cannot be cast to java.lang.String
        at CS$1.apply(CS.java:1)
        at ...

        it should not throw an exception instead.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  attila Attila Szegedi
                  Reporter:
                  attila Attila Szegedi
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: